In the above example, we import matplotlib.pypot and numpy as a library.Plot_2 = ax2.plot(x, data_2, color = 'green')Īx2.tick_params(axis ='y', labelcolor = 'green') Plot_1 = ax1.plot(x, data_1, color = 'black')Īx1.tick_params(axis ='y', labelcolor = 'black')Īx2.set_ylabel('Y2-axis', color = 'green') Let’s see an example of two y-axes with different left and right scales: # Import LibraryĪx1.set_ylabel('Y1-axis', color = 'black') It simply means that two plots on the same axes with different y-axes or left and right scales.īy using the Axes.twinx() method we can generate two different scales.
#Veusz plot with two y axes how to
Here we are going to learn how to plot two y-axes with different scales in Matplotlib. Python plot multiple lines using Matplotlib.plt.legend() method is used to add legend to the plot.After this, we use twinx() method is used to create two y-axis.Then we plot data by using plot() method and pass label as an argument to define legends.Next we define, data using arrange(), sin(), and cos() method.Plot_2 = ax2.plot(x, data_2, color = 'blue', label = 'Cos x') Plot_1 = ax1.plot(x, data_1, color = 'red', label='Sin x')
![veusz plot with two y axes veusz plot with two y axes](https://www.djmannion.net/psych_programming/_images/i4b.png)
Let’s see an example to better understand the concept: # Import Library In matplotlib, by using the plt.legend() method we can add legends to the plot. twinx() method is used to create two y-axis.After this, we plot data between x-axis and y2-axis by using plot() method.Then we plot data between x-axis and y1-axis by using plot() method.Next we define data using arrange(), sin(), and cos() method.In the above example, we firstly import numpy and matplotlib.pyplot library.Let’s see an example where we create two y-axes: # Import LibraryĪx1.tick_params(axis ='y', labelcolor = 'red')Īx2.set_ylabel('Y2-axis', color = 'blue')Īx2.tick_params(axis ='y', labelcolor = 'blue') The syntax of the twinx() method is as given below: (self) In matplotlib, the twinx() function is used to create dual axes. When we need a quick analysis, at that time we create a single graph with two data variables with different scales.
![veusz plot with two y axes veusz plot with two y axes](http://4.bp.blogspot.com/-1lGvVE-1VKQ/VMMUtF1mOGI/AAAAAAAABOI/zx5QalxwHPU/s1600/f1m.png)
In this section, we learn about how to plot a graph with two y-axes in matplotlib in Python. Matplotlib two y axis grid Matplotlib two y axes