简体   繁体   中英

Why my boxplot is not showing up on a pop-up screen?

Question: Why my boxplot chart is not showing up? The code just finishes running and no pop-up screen appears with the boxplot chart. Thanks

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()

Output of print(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]

I tested out your code and tried out a few tweaks. The simple answer is that you needed to create a boxplot variable and add in the following line of code to your program.

boxplot = df.boxplot(column=["time"],by="steps", rot=90)
boxplot.plot()

Following is my test version of your code for you to experiment with. Since I did not have an actual set of data, I generated some values that would seem to fit the spirit of your code for your data frame.

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()

With that additional bit of code, I got a chart to display.

箱线图

Hope that helps.

Regards.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM