我正在尝试格式化matplotlib图像,以便状态缩写“PR”出现在其他状态之前。我的图像保持按字母顺序排列标记,以便“AR”始终是第一个,但即使这样,标记标签顺序也是随机的,并且不是完全按字母顺序排列。
gun_states = [gun_pr_count,gun_al_count,gun_ak_count,gun_ar_count,gun_az_count,gun_ca_count,gun_co_count,gun_ct_count,gun_de_count,
gun_dc_count,gun_fl_count,gun_ga_count,gun_hi_count,gun_id_count,gun_il_count,gun_in_count,gun_ia_count,gun_ks_count,
gun_ky_count,gun_la_count,gun_me_count,gun_md_count,gun_ma_count,gun_mi_count,gun_mn_count,gun_ms_count,gun_mo_count,
gun_mt_count,gun_ne_count,gun_nv_count,gun_nh_count,gun_nj_count,gun_nm_count,gun_ny_count,gun_nc_count,gun_nd_count,
gun_oh_count,gun_ok_count,gun_or_count,gun_pa_count,gun_ri_count,gun_sc_count,gun_sd_count,gun_tn_count,gun_tx_count,
gun_ut_count,gun_vt_count,gun_va_count,gun_wa_count,gun_wv_count,gun_wi_count,gun_wy_count]
state_names = ["PR","AL","AK","AR","AZ","CA","CO","CT","DE","DC","FL","GA","HI","ID","IL","IN","IA","KS","KY","LA","ME","MD","MA",
"MI","MN","MS","MO","MT","NE","NV","NH","NJ","NM","NY","NC","ND","OH","OK","OR","PA","RI","SC","SD","TN","TX","UT",
"VT","VA","WA","WV","WI","WY"]
plt.figure(figsize=(20,3))
plt.bar(state_names,gun_states)
plt.xticks(state_names)
plt.xlabel("State")
plt.ylabel("Gun Sale Licenses")
plt.title("Number of Gun Sale Licenses per State")
plt.show()
这是我目前的输出: