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

preview_player
Показать описание
Do you want to learn how to add second y-axis in Matplotlib? In this Matplotlib tutorial I have explained how to plot a graph in Matplotlib with two y-axis. I have also shown practical examples step by step of adding second y-axis in Matplotlib.
In addition, I have covered the following topics related to Matplotlib's secondary y-axis:
1. Matplotlib secondary y-axis limits
2. Matplotlib secondary y-axis label
3. Matplotlib secondary y-axis subplot
4. Matplotlib secondary y-axis histogram
5. Matplotlib secondary y-axis color
6. Matplotlib secondary y-axis ticks
==========================================
==========================================
Related Video Tutorials:
==========================================
==========================================
Subscribe to Our YouTube Channel for more videos tutorials
==========================================
Playlists for You:
==========================================
Do Visit Our Website
==========================================
#python #matplotlib #matplotliby-axis #dualy-axis #matplotlibgraph
Рекомендации по теме
Комментарии
Автор

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

bennguyen