我的代码如下:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
data=pd.read_csv("C:/Users/Jagdeep/Downloads/Alokji political data/political plot data parliamentary.csv")
fig=plt.figure()
ax = fig.add_subplot(111)
plt.plot(parl_data['BJP'], marker='o', label='BJP', color='red')
plt.plot(parl_data['INC'], marker='o', label='INC', color='blue')
plt.plot(parl_data['AAP'], marker='o', label='AAP', color='brown')
plt.plot(parl_data['Total_Polling'], marker='o', label='Total
Polling', color='green', linestyle='dashed')
plt.legend()
for i,j in parl_data.BJP.items():
ax.annotate(str(j), xy=(i, j))
for i,j in parl_data.INC.items():
ax.annotate(str(j), xy=(i, j))
for i,j in parl_data.AAP.items():
ax.annotate(str(j), xy=(i, j))
for i,j in parl_data.Total_Polling.items():
ax.annotate(str(j), xy=(i, j))
ax.set_alpha(0.8)
ax.set_title("Party-wise vote share in Lok Sabha Polls (Delhi) 2019",
fontsize=15)
ax.set_ylabel("Parliament Polling Percentage", fontsize=15);
ax.set_xlabel("Election Year", fontsize=15)
ax.set_xticklabels(['2004','2009','2014','2019'])
plt.yticks(np.arange(0,100,10))
plt.show()
我是Python和数据科学的新手。我应该如何在图表的x轴上添加2004200920142019年?我要轮询%vs年图。在使用代码时,我无法在x轴上绘制年份
我已经注释了添加输入的所有行。我希望这就是你想要的
选项1(线图):
情况如下:
选项2(条形图+直线):
输出如下:
相关问题 更多 >
编程相关推荐