Matplotlib Adding Second Y-Axis | How To Plot With 2 Y-axis in 1 Graph in Matplotlib

Matplotlib Adding Second Y-Axis | How To Plot With 2 Y-axis in 1 Graph in Matplotlib

TSInfo Technologies

11 месяцев назад

171 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@bennguyen1313
@bennguyen1313 - 01.12.2023 07:40

I understand that a 2nd series of data, with it's own scale can be done using twinx..
ax2 = ax1.twinx()

But you can also create just another spine (with new scaling) for either of the y axis data using:
ax1b = ax1.secondary_yaxis(-0.25, # places new spine to the left of ax1!
ax2b = ax2.secondary_yaxis(-0.25,

However, none of my data is correlated with each other so I can't use secondary_yaxis. I'm trying to plot the DATE on the X-Axis, and then Temperature, Humidity, Pressure, and UV-Index on 4 Y-axis (same figure-no subplots)

I'd like for the spine and legend for the Temperature to be on the left most side of the window, followed by the Humidity to its right (left of the plot window). The Pressure and UV spines/legends would be on the right side of the plot area: T H [ plots ] P UV

For some reason, the set_position always places the Temperature axis to the right of the Humidity axis:
axTemp = axHumidity.twinx()
axTemp.spines['left'].set_position(('axes',0.01)) # places new spine to the right of axHumidity (inside the plot area)
axTemp.spines['left'].set_position(('axes',-1)) # places new spine to the right of the axHumidity

Ответить