matplotlib中的直方图的X轴乱序

时间:2018-10-30 19:11:47

标签: python matplotlib histogram

尽管该列的dtype是int64,但x轴仍然不正确。我什至尝试按升序对dataframe列进行排序。但这没用。

csv_path ="https://people.sc.fsu.edu/~jburkardt/data/csv/snakes_count_100.csv"
df3 = pd.read_csv(csv_path, usecols=[' "Game Length"'])
df3 = df3[1:51]
#df3.head()
ax = plt.axes()
plt.setp(ax.get_xticklabels(), rotation=30, horizontalalignment='right')
plt.hist(df3)
plt.legend()
plt.title('Game of snakes')
plt.ylabel('Frequency')
plt.xlabel('Game Length')

https://ibb.co/mWaBHf

1 个答案:

答案 0 :(得分:0)

您可以使用hist类本身的DataFrame方法。

通过对命令进行一些重新排序,您可以坚持执行其余代码:

csv_path ="https://people.sc.fsu.edu/~jburkardt/data/csv/snakes_count_100.csv"
df3 = pd.read_csv(csv_path, usecols=[' "Game Length"'])
df3 = df3[1:51]
df3.hist()
ax = plt.axes()
plt.setp(ax.get_xticklabels(), rotation=30, horizontalalignment='right')
plt.legend()
plt.title('Game of snakes')
plt.ylabel('Frequency')
plt.xlabel('Game Length')