我曾尝试使用matplotlib
绘制条形图,但在编写代码以显示标题和xlabel ylabel时,它们没有显示。我做错什么了?你知道吗
我已经创建了一个数据帧,并尝试使用df.plot(...)
绘制相同的数据帧。
但是我没有得到标签选项和xticks。所以我试了这个。你知道吗
# Make a fake dataset:
districts = ['Alappuzha','Ernakulam','Idukki','Kannur','Kasaragod','Kollam','Kottayam','Kozhikode','Malappuram','Palakkad','Pathanamthitta','Thiruvananthapuram','Wayanad','Thrissur']
distAb = ['Alp','Ern','Idk','Knr','Ksd','Klm','Ktm','Kzd','Mlp','Plk','Pta','Tvm','Wyd','Tsr']
population = [2121943,3279860,1107453,2525637,1302600,2629703,1979384,3089543,4110956,2810892,1195537,3307284,816558,3110327]
posArrange = np.arange(len(districts))
plt.bar(posArrange,population,color='#ff9900', width=.8)
plt.title='Population of Districts in Kerala'
plt.xlabel='Districts'
plt.ylabel='Population'
plt.xticks(posArrange,distAb)
plt.show()
输出不是我所期望的。它没有显示xlabel、ylabel和标题。 enter image description here
我已经在我的项目中使用了下面的代码,它正在工作。你可以这样用
title
、xlabel
、ylabel
和xticks
是函数,这意味着它们后面有带参数的方括号。 相应地更改以下行,您应该可以在绘图中看到所需的元素。你知道吗相关问题 更多 >
编程相关推荐