這個簡單的代碼繪製預期折線圖:爲什麼matplotlib開始繪製的條形圖,而不是線圖
james_f=names[(names.name=='James') & (names.sex=='F')]
plt.plot(james_f['year'],james_f['births'])
plt.show()
但後來我改變狀態,只需刪除其中的一個,然後它開始繪製條形圖。爲什麼以及如何強制繪製折線圖?
james_f=names[(names.name=='James')]
plt.plot(james_f['year'],james_f['births'])
plt.show()
增加,而不是它1 == 1條規則,沒有什麼變化(
james_f=names[(names.name=='James') & (1 == 1)]
plt.plot(james_f['year'],james_f['births'])
plt.show()
即使這個代碼繪製條形圖:
james_f=names[(names.name=='James') | (names.name=='John') | (names.name=='Robert') ]
plt.plot(james_f['year'],james_f['births'])
james_f['births']
輸出(大熊貓。 core.series.Series):
228 46
343 22
538 11
942 9655
944 5927
2312 26
2329 24
2617 9
2938 8769
....
Name: births, dtype: int64
james_f['births'].min()
回7沒有零或NaN值
>>> print(james_f[james_f['births'].isnull()])
Empty DataFrame
Columns: [name, sex, births, year]
Index: []
>>> james_f.head(10)
name sex births year
343 James F 22 1880
944 James M 5927 1880
2329 James F 24 1881
2940 James M 5441 1881
4372 James F 18 1882
4965 James M 5892 1882
6428 James F 25 1883
7118 James M 5223 1883
8488 James F 33 1884
9320 James M 5693 1884
看起來你的數據中有一些零而不是matplotlib改變它的行爲。在有問題的情況下,james_f ['births']的輸出是什麼? –
'james_f ['births']'的輸出是什麼? –
@TillHoffmann更新信息 – Rocketq