我想在Jupyter筆記本中為一個資料集繪制直方圖,其最小值為~8e 01,最大值為6e 07,平均值為~8e 05,中位數為~1e 05,而模式為~2e 03。我還想在圖中顯示中心趨勢線。這是我的代碼:
plt.figure(figsize=(7, 5)
sns.kdeplot(dataset, shade=True)
plt.vlines(x=np.mean(dataset), ymin=0, ymax=1, color='blue'/span>, linestyle='--'/span>)
plt.vlines(x=np.median(dataset), ymin=0, ymax=1, color='棕色', linestyle='--')
plt.vlines(x=scp. mode(dataset)[0][0], ymin=0, ymax=1, color='red'/span>, linestyle='--'/span>)
plt.legend(['資料集', '平均值', '中位數', '模式'], fontsize=12)
plt.show()
無論如何,結果圖是:
我在網上搜索了一下,但我找到的所有答案要么是添加plt.show(),我已經做了,要么是%matplotlib inline,這只適用于IPython筆記本。我想不出其他的原因,為什么圖表不能正確顯示資料。
測驗資料集:
596819.4。
642682.4[/span
619509.33
649141.25
545800.05
572019.8[/span]718330.48
830967.23
742220.67
656892.03
1005603.78
653560.14
657444.04
696281.81
709268.62
924993.61
823623.36
734721.29
783935.36
882754.72
821523.45
800603.23
772926.12
800194.34
850931.58
uj5u.com熱心網友回復:
- 這是因為
ymax=1被指定了;kdeplot的y軸的最大值是3e-06。密度曲線就在那里,只是由于vlines的比例而無法看到。p = sns.kdeplot(ds, shade=True, label='Dataset') p.axvline(x=np. mean(ds) , ymin=0, ymax=1, color='blue' , linestyle='--'/span>, label='Mean'/span>) p.axvline(x=np. median(ds), ymin=0, ymax=1, color='棕色', linestyle='--', label='Median') p. axvline(x=mode(ds)[0][0], ymin=0, ymax=1, color='red', linestyle='--', label='Mode') p.legend(fontsize=12) plt.show()
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/328939.html標籤:
上一篇:回圈中的Python圖譜被覆寫了


