Matplotlib multiple y-axis pandas-DiagrammPython

Python-Programme
Anonymous
 Matplotlib multiple y-axis pandas-Diagramm

Post by Anonymous »

Ich möchte mehrere Y -Achsen -Diagramme machen. Ich versuche, das gleiche Erscheinungsbild und das gleiche Gefühl dieser Antwort zu erhalten. Muss ich einen ax.twinx () für jedes separate y -Achsendiagramm definieren, das ich brauche?

Code: Select all

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

rows,cols = 8760,4
data = np.random.rand(rows,cols)
tidx = pd.date_range('2019-01-01', periods=rows, freq='H')
df = pd.DataFrame(data, columns=['Temperature','Value1','Pressure','Value2'], index=tidx)

# using subplots() function
fig, ax = plt.subplots(figsize=(25,8))
plt.title('Multy Y Plot')

ax2 = ax.twinx()
ax3 = ax.twinx()
ax4 = ax.twinx()

plot1, = ax.plot(df.index, df.Temperature)
plot2, = ax2.plot(df.index, df.Value1, color = 'r')
plot3, = ax3.plot(df.index, df.Pressure, color = 'g')
plot4, = ax4.plot(df.index, df.Value2, color = 'b')

ax.set_xlabel('Date')
ax.set_ylabel('Temperature')
ax2.set_ylabel('Value1')
ax3.set_ylabel('Pressure')
ax4.set_ylabel('Value2')

plt.legend([plot1,plot2,plot3,plot4],list(df.columns))

# defining display layout
plt.tight_layout()

# show plot
plt.show()
Dies gibt alles auf derselben Seite ohne separate y -Achse für Druck, Wert1 und Wert 2 aus.>

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post