我绘制了一张用python显示邮政编码和疫苗的图形,但是当我尝试在条形图中复制这些图形和疫苗时,我不断遇到值错误:形状不匹配:对象无法广播为单个形状。 请在下面查看我的第一个代码和第二个代码:
import numpy as np
import matplotlib.pyplot as plt
plt.close()
plt.plot(zipin2016,vaccovin2016,Label='Population that received flu shots per zipcode', color='purple')
plt.xticks(rotation=45)
plt.xlabel('zipcodes')
plt.ylabel('population')
plt.title('vaccine coverage in 2016 for Illinois')
plt.legend()
plt.show()
这是我用来绘制条形图的代码,但是它不起作用:
myx = [60601, 60602, 60603, 60604, 60605, 60606, 60607, 60608, 60609, 60610, 60611, 60612, 60613, 60614, 60615, 60616, 60617, 60618, 60619, 60620, 60621, 60622, 60623, 60624, 60625, 60626, 60628, 60629, 60630, 60631, 60632, 60633, 60634, 60636, 60637, 60638, 60639, 60640, 60641, 60642, 60643, 60644, 60645, 60646, 60647, 60649, 60651, 60652, 60653, 60654, 60655, 60656, 60657, 60659, 60660, 60661, 60706, 60707, 60714, 60804, 60827]
vaccovin2016 = [2161.0, 27.0, 146.0, 30.0, 4801.0, 650.0, 13590.0, 35740.0, 30715.0, 18364.0, 10251.0, 14683.0, 19537.0, 25306.0, 17430.0, 18194.0, 37215.0, 37934.0, 28973.0, 33150.0, 18364.0, 29380.0, 41798.0, 17643.0, 35307.0, 22901.0, 33945.0, 44055.0, 21173.0, 11144.0, 33849.0, 5126.0, 28664.0, 19886.0, 22065.0, 21562.0, 35926.0, 28613.0, 28533.0, 0.0, 20318.0, 22826.0, 17082.0, 10442.0, 38174.0, 21189.0, 29986.0, 15122.0, 13335.0, 3.0, 11262.0, 10485.0, 25814.0, 15133.0, 18446.0, 1694.0, 8816.0, 16473.0, 12001.0, 33290.0, 12835.0]
zipp=np.arange(60601,60828,5)
plt.bar(zipp,vaccovin2016,Label='Population that received flu shots per zipcode')
plt.xticks(rotation=45)
plt.xlabel('zipcodes')
plt.ylabel('population')
plt.title('vaccine coverage in 2016 for Illinois')
plt.legend()
plt.show()