0

For a little jupyter notebook widget i tried the following:

with output:
    fig, ax = plt.subplots(constrained_layout=True, figsize=(6, 4))
     
# move the toolbar to the bottom
fig.canvas.toolbar_position = 'bottom'
ax.grid(True)  
line, = ax.plot(df.index, init_data, initial_color,)
ax.set_ylabel('CH4_HYD1')
ax.set_ylabel('')

But the data gets plotted in a wierd way. When isolating the plotting method and comparing it to the pandas default, the pandas plot displays the data correctly.

df['CH4_HYD1'].plot()

Pandas plot
enter image description here

plt.plot(['CH4_HYD1'])

Wrong plot? enter image description here

I would like to use the axis plot method to produce a plot with multiple lines of different features. But I can't find the probably very simple error... What is the difference here?

Mr. T
  • 11,960
  • 10
  • 32
  • 54
  • Could you upload your DataFrame as well? It seems to be a problem with the indexing. – Shir Mar 05 '21 at 09:57
  • What is "the pandas default"? What is your input? Please read [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask) and [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples), then edit the question. – Mr. T Mar 05 '21 at 10:00
  • Hey, thanks, there was an error in the indexind, I messed up there. Thanks for the hint! How can i close such a question? – Imre Antalfy Mar 05 '21 at 10:49

1 Answers1

-1

This is a short example of how to plot multiple lines from a DataFrame with matplotlib and with pandas. Essentially, pandas uses matplotlib to do the plots so it shouldn't be different.

enter image description here

Anyway, I encourage you to look into seaborn. This is a great library based on pandas and matplotlib that enables visualizing dataframes easily.

Shir
  • 1,571
  • 2
  • 9
  • 27