try plotting an iteration but plt.plot is empty

grove park
a = frame_query("select ....",db)

With my code, the var 'c' is a numpy.ndarray which I would like to plot. However when I execute the following code, i get an empty plot!

for i in a.values:
    c = (i[:1]-a.values[-1:])/a.values[-1:]*100
    plt.plot(c)
plt.show()

print c

gives:

[[ 28.57142857]]
[[ 27.27272727]]
[[ 27.92207792]]
[[ 28.57142857]]
[[ 22.07792208]]
[[ 22.07792208]]
[[ 22.07792208]]

Where exactly am I going wrong?

Thank you in advance.

J Richard Snape

The simplest way to adapt your code is probably to start an empty list before the loop, append the values from c onto it within the loop and then plot it after the loop. For example:

c_series = []

for i in a.values:
    c = (i[:1]-a.values[-1:])/a.values[-1:]*100
    c_series.append(c[0])

plt.plot(c)
plt.show()

Note using c[0] is safe here, because the logic of the line above guarantees that the ndarray will only have one member.

However, that's a bit of an odd way to deal with your data structure. As it seems that a.values is an ndarray, you could also simply do this by using the facilities that numpy provides to perform arithmetical operations on arrays (I can't test it as I don't have a verbatim copy of your a.values):

const = a.values[-1:]
c_series = (a.values - const) / const*100
plt.plot(c_series)
plt.show()

In general - when using numpy arrays, it's often better to keep them as arrays (called vectorising the code), rather than dealing with them element by element in a loop.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

GNUplot batch plotting producing empty plot files

分類Dev

plt.show() is empty when the plt.plot() calls are done in other cells

分類Dev

Geopandas plot empty when changing crs and plotting with fig,ax (without fig,ax everything is fine)?

分類Dev

ggplot violin plot is not plotting

分類Dev

what's the difference between plt.plot(), object.plot()

分類Dev

R circlize - plot margins and plotting regions

分類Dev

Python saving empty plot

分類Dev

Matplotlib: Check for empty plot

分類Dev

Bokeh plot is empty

分類Dev

[:、0]と[:、1]のplt.plotの意味

分類Dev

sharey='all' argument in plt.subplots() not passed to df.plot()?

分類Dev

plt.plot draws multiple curves instad of single curve

分類Dev

Why does this render an empty plot?

分類Dev

plt.plot()、object.plot()の違いは何ですか

分類Dev

sympy.plotting.plot奇妙なxlabelの位置

分類Dev

Plotting mean lines for different 'hue' data on a Seaborn FacetGrid plot

分類Dev

How to identify where is the error in the Q-Q plot plotting?

分類Dev

Plotting three data sets on a single plot using matplotlib

分類Dev

Change plot label when plotting different dataframes in pandas

分類Dev

Kmeans matlab "Empty cluster created at iteration 1" error

分類Dev

geom_rect gives empty plot with no rectangle

分類Dev

bokeh plot empty when rendering Flask template

分類Dev

plt.plotの前にplt.figure()を使用しても、エラー<図サイズ1000x600、1軸>

分類Dev

plt.plot()呼び出しが他のセルで行われる場合、plt.show()は空です。

分類Dev

Matplotlibのplt.plot()プロットのように動作するplt.scatter()プロット

分類Dev

plotting single 3D point on top of plot_surface in python matplotlib

分類Dev

Python 4D plot using matplotlib- confusion in reading and plotting the array

分類Dev

Overlaying matplotlib plot from multiple function calls while also plotting them separately

分類Dev

Overlaying matplotlib plot from multiple function calls while also plotting them separately

Related 関連記事

  1. 1

    GNUplot batch plotting producing empty plot files

  2. 2

    plt.show() is empty when the plt.plot() calls are done in other cells

  3. 3

    Geopandas plot empty when changing crs and plotting with fig,ax (without fig,ax everything is fine)?

  4. 4

    ggplot violin plot is not plotting

  5. 5

    what's the difference between plt.plot(), object.plot()

  6. 6

    R circlize - plot margins and plotting regions

  7. 7

    Python saving empty plot

  8. 8

    Matplotlib: Check for empty plot

  9. 9

    Bokeh plot is empty

  10. 10

    [:、0]と[:、1]のplt.plotの意味

  11. 11

    sharey='all' argument in plt.subplots() not passed to df.plot()?

  12. 12

    plt.plot draws multiple curves instad of single curve

  13. 13

    Why does this render an empty plot?

  14. 14

    plt.plot()、object.plot()の違いは何ですか

  15. 15

    sympy.plotting.plot奇妙なxlabelの位置

  16. 16

    Plotting mean lines for different 'hue' data on a Seaborn FacetGrid plot

  17. 17

    How to identify where is the error in the Q-Q plot plotting?

  18. 18

    Plotting three data sets on a single plot using matplotlib

  19. 19

    Change plot label when plotting different dataframes in pandas

  20. 20

    Kmeans matlab "Empty cluster created at iteration 1" error

  21. 21

    geom_rect gives empty plot with no rectangle

  22. 22

    bokeh plot empty when rendering Flask template

  23. 23

    plt.plotの前にplt.figure()を使用しても、エラー<図サイズ1000x600、1軸>

  24. 24

    plt.plot()呼び出しが他のセルで行われる場合、plt.show()は空です。

  25. 25

    Matplotlibのplt.plot()プロットのように動作するplt.scatter()プロット

  26. 26

    plotting single 3D point on top of plot_surface in python matplotlib

  27. 27

    Python 4D plot using matplotlib- confusion in reading and plotting the array

  28. 28

    Overlaying matplotlib plot from multiple function calls while also plotting them separately

  29. 29

    Overlaying matplotlib plot from multiple function calls while also plotting them separately

ホットタグ

アーカイブ