問題:為什么我的箱線圖沒有顯示?代碼剛剛完成運行,箱線圖不會出現任何彈出螢屏。謝謝
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
df = pd.DataFrame(triesAndTime, columns = ["steps", "time"])
df.boxplot(column=["steps", "time"], rot=90)
plt.show()
列印輸出(df):
steps time
0 4790 0.255929
1 2450 0.254098
2 10466 0.341369
3 821 0.223506
4 10225 0.291951
.. ... ...
95 2925 0.270130
96 215577 2.398803
97 43084 0.598177
98 34837 0.584912
99 5826 0.253654
[100 rows x 2 columns]
uj5u.com熱心網友回復:
我測驗了您的代碼并嘗試了一些調整。簡單的答案是您需要創建一個箱線圖變數并將以下代碼行添加到您的程式中。
boxplot = df.boxplot(column=["time"],by="steps", rot=90)
boxplot.plot()
以下是我的代碼測驗版本供您試驗。由于我沒有一組實際的資料,因此我生成了一些似乎符合資料框架代碼精神的值。
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
steps=[4790, 2450, 10466, 821, 10225]
time=[0.255929, 0.254098, 0.341369, 0.223506, 0.291951]
#Manually pushed in my data as I did not have the structure of your "timeAndTries" variable
df = pd.DataFrame({'steps':steps , 'time': time}, columns = ["steps", "time"])
boxplot = df.boxplot(column=["time"],by="steps", rot=90) #tweaked this line to create variable "boxplot"
boxplot.plot() # This seemed to be the missing piece
plt.show()
使用那額外的代碼,我得到了一個要顯示的圖表。

希望有幫助。
問候。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/495120.html
標籤:Python 熊猫 matplotlib
上一篇:如何在單個圖中創建子圖組
