Home > Enterprise >  Why Python throws "<pyqtgraph.graphicsItems.PlotDataItem.PlotDataItem at 0x1dc1a1bf670>&q
Why Python throws "<pyqtgraph.graphicsItems.PlotDataItem.PlotDataItem at 0x1dc1a1bf670>&q

Time:07-13

I created the following df that contains the following data:

    True Price Range
0   0.3151260504201625
1   0.08403361344537472
2   0.3577441077441151
3   0.2773629187113253
4   0.1715633712202524
5   0.4948364888123946
6   0.30068728522337035
7   0.043261951113993474
8   0.4562242016076512
9   0.1527050610820258
10  0.2185314685314596
11  0.9452626950978232
12  0.459016393442627
13  0.48097944905989937
14  0.17459624618071515
15  0.39534372940917983
16  0.44130626654898236
17  0.440237728373319
18  0.4386926957666129
19  0.4149377593361054
20  0.08748906386702823
21  0.21920210434019272
22  6.046511627906989
23  0.1536772777167961
24  0.06590509666081337
25  0.021987686895345346
26  0.46337157987643834
27  0.3077599472411393
28  0.043907793633368136
29  0.17644464049405312
30  0.29082774049218146
31  0.3157419936851629
32  0.49762497172584935
33  0.24797114517584748
34  0.49571879224875615
35  0.2941842045711658
36  0.49661399548532276
37  0.6515389800044902
38  0.4916201117318546
39  0.6037567084078699
40  1.1599375418246702
41  0.2668445630420171
42  0.28882470562096907
43  0.3771073646849967
44  0.17742293191395805
45  0.022158209616654382
46  0.46532240194991115
47  0.3576218149307117
48  0.15642458100558798
49  0.27008777852802623
50  0.3161698283649531
51  0.18289894833103962
52  0.7097069597069705
53  0.5325306783977797
54  0.13879250520472936
55  0.3940658321743243
56  0.1391465677180067
57  0.301694128568109
58  0.1860897883228582
59  0.1638193306810218

I'm trying to plot its corresponding boxplot, based on this guide, I can run df["True Price Range"].plot(kind='box', title='Boxplot of True Price Range') in the Spyder console to get that.

But after doing so, I get the following output:

Out[3]: <pyqtgraph.graphicsItems.PlotDataItem.PlotDataItem at 0x1dc1a1bf670>

Which I don't understand, I also tried:

df["True Price Range"].plot(kind='box', title='Boxplot of True Price Range').show()

And got literally nothing as output, not even errors.

Finally I tried using the Pandas boxplot function (i.e. df.boxplot(column= "True Price Range")) and got the following error:

AttributeError: module 'finplot.pdplot' has no attribute 'boxplot_frame'

Note: Both matplotlib.pyplot and pandas libraries were imported as pd and plt respectively before running the syntax above

May I get some assistance here?

CodePudding user response:

Regarding your first command, the output you get is simply the object type that you have created (pyqtgraph.graphicsItems.PlotDataItem.PlotDataItem) and the memory address where this object is located (0x1dc1a1bf670). There is nothing wrong with this output. If you want to see the plot, you should add plt.show() after this command. Therefore, the code should be:

df["True Price Range"].plot(kind='box', title='Boxplot of True Price Range')
plt.show() # displays the figure

The matplotlib.pyplot.show function displays the figure that you have created.

Regarding the line df["True Price Range"].plot(kind='box', title='Boxplot of True Price Range').show(), you shouldn't call the show method on the object you have just created (i.e., the pyqtgraph.graphicsItems.PlotDataItem.PlotDataItem type). Just call the show method as mentioned above.

Regarding the AttributeError you mention last, it means that the method you want to call does not exist.

CodePudding user response:

Solved by running the following lines:

plt.boxplot(x=df, vert = False)
plt.show() # displays the figure

matplotlib.pyplot must have been imported as plt

  • Related