python matplotlib two y axis

import numpy as np
import matplotlib.pyplot as plt

# Create some mock data
t = np.arange(0.01, 10.0, 0.01)
data1 = np.exp(t)
data2 = np.sin(2 * np.pi * t)

fig, ax1 = plt.subplots()

color = 'tab:red'
ax1.set_xlabel('time (s)')
ax1.set_ylabel('exp', color=color)
ax1.plot(t, data1, color=color)
ax1.tick_params(axis='y', labelcolor=color)

ax2 = ax1.twinx()  # instantiate a second axes that shares the same x-axis

color = 'tab:blue'
ax2.set_ylabel('sin', color=color)  # we already handled the x-label with ax1
ax2.plot(t, data2, color=color)
ax2.tick_params(axis='y', labelcolor=color)

fig.tight_layout()  # otherwise the right y-label is slightly clipped
plt.show()

3.78
9
A. M. 130 points

                                    import numpy as np
import matplotlib.pyplot as plt
x = np.arange(0, 10, 0.1)
y1 = 0.05 * x**2
y2 = -1 *y1

fig, ax1 = plt.subplots()

ax2 = ax1.twinx()
ax1.plot(x, y1, 'g-')
ax2.plot(x, y2, 'b-')

ax1.set_xlabel('X data')
ax1.set_ylabel('Y1 data', color='g')
ax2.set_ylabel('Y2 data', color='b')

plt.show()

3.78 (9 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
pyplot add second y axis python matplotlib add second y axis second y scale matplotlib matplotlib plt plot make second y axis second y-axis matplotlib matplotlib plot on second y axis matplotlib second x axis below second y axis matplotlib plot second axis python second y axis matplitlub plt.second axis set second y axis matplotlib pyplot second y axis labeld matplotlib 2 axis one figure add second y axis matplotlib double y axis python python matplotlib two y axis matplotlib plot two different y axis matplot lib scatter plot in different axis varying scale for the y axis in matplotlib matplotlib making a plot with 2 y axis maplotlib plot graph with different axis sizes python plot with two y axis BOKAE python plot with two y axis plot on different axis python matplotlib two axes matplotlib plot two lines with different y axis matplotlib add second y axis secondary y axis plt plot multiple lines with different scales matplotlib how to plot charts for two axis in matplotlib secondary y axis matplotlib 2 y axis in matplotlib ggplot second y axis scale python plot two graphs with different scale python matplotlib second y axis combine top two plots in matplotlibe 2 * 2 subplots python second y axis matplotlib plot with two different y axis matplotlib 2 y axis matplotlib with 2 y axes drawing secondary axis in scatter plots in matplotlib drawing secondary axis in matplotlib matplotlib separate y labels matlotlib different axis different axis .plot plot right away pyplot how to name y axis with two axis in python matplotlib second y axis plot matplotlib graph with differnt axis values use second y axis plt add secondary x scale on a plot in python secondary axis pyplot secondary axis label matplotlib matplotlib pyplot plot multiple axes plot two x axis matplotlib matplotlib two plots different y axis how to add secondary axis in python matplotlib make scales of two plots equal add secondary axis python add a second axis in python matplotlib with two axis plt plot two axis y plot on secondary axis matplotlib plot two graphs with different sacle python python plot same axis example dual axis plot in python plot 2 axis python two axis plot matplotlib double axis mathplotlib matplotlib diffrante scale axis how to make 2 plot in 1 with two y labels matplotlib matplotlib dual axis lines 2 axis on same graph matplot plot 2 y axis python plot two different scales matplotlib multiple plot with different scales in matplotlib pyplot multiple axes plot secondary y axis matplotlib how to plot on secondary axis in python plot how to plot 2 axis matplotlib 2nd y label on right matplotlib name secondary axis in python add secondary y axis python matplotlib dual y axis how to plot wo plots with different axis python python dual y axis plot two y axis python matplotlib different y axis matplotlib 2 y plot multiple axis matplotlib matplotlib multiple y axes pyplot multiple y axes plot double y axis python plt python how to create 2 axis plot why my plot have double x-axis python matplotlib dual axis plt 2 axes how to plot with two y axis in python matplotlib double y axis with mutiple each plotting two y axis on top of the same plot python second axis matplotlib y axis dual axis chart python plt.plot secondary y axis make a second y axis wth clone x matplotlib plotting extra axis on right matplotlib how to create a graph with two y axis in matplotlib python matplotlib secondary y axis two axis graph with matplotlib secondary y label matplotlib secondary axis python add y axus matplotlib python plot on secondary axis matplotlib multiple axes how to plot left and right y axis with x axis in python different scale for y ax in matplotlib python 2 line plots with different scales two y axis in python python two y axis second axis matplotlib 2 y axis plot matplotlib how to add a secondary azis python how to add a secondary axis in python matplot matplotlib two axis single plot pyplot dual axis two y axis matplotlib matplotlib right axis python plot 2 y axis ax2 in python how to get two y axis in python plotyy python python matplotlib how to make 2 axis graph add another axis python add already plotted axes on another axes python python plot double y axis drawing a graphs in python with different scale two y axis plt python python dual axis plot secondary Y-axis in axes different scale in matplotlib plt plot two y axis two axis matplotlib matplotlib line different scales matplotlib line differente scalers python plot 2 axis matplotlib plot different scales matplotlib double yaxis plot matplotlib double axis plot ax2 = ax1.twinx() python plot two lines different scales matplotlib plot twin double y axis matplotlib matplotlib pyplot set second y axis label matplotlib double y axis matplotlib two y axes plot with two y axis python python matplotlib second y axis label how to plot graphs with different scale in python how to plot two y axis in python plot two axes python python plot two y axis python plot different left and right y axis python double y axis python graphing two axis on same scale matplotlib python plotting two y axis with different scale with same x axis pyplot second y axis
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source