Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

plt datas use left and right yaxes

# import libraries
import numpy as np
import matplotlib.pyplot as plt
 
# Creating dataset
x = np.arange(1.0, 100.0, 0.191)
dataset_1 = np.exp(x**0.25) - np.exp(x**0.5)
dataset_2 = np.sin(0.4 * np.pi * x**0.5) + np.cos(0.8 * np.pi * x**0.25)
 
# Creating plot with dataset_1
fig, ax1 = plt.subplots()
 
color = 'tab:red'
ax1.set_xlabel('X-axis')
ax1.set_ylabel('Y1-axis', color = color)
ax1.plot(x, dataset_1, color = color)
ax1.tick_params(axis ='y', labelcolor = color)
 
# Adding Twin Axes to plot using dataset_2
ax2 = ax1.twinx()
 
color = 'tab:green'
ax2.set_ylabel('Y2-axis', color = color)
ax2.plot(x, dataset_2, color = color)
ax2.tick_params(axis ='y', labelcolor = color)
 
# Adding title
plt.title('Use different y-axes on the left and right of a Matplotlib plot', fontweight ="bold")
 
# Show plot
plt.show()
Comment

PREVIOUS NEXT
Code Example
Python :: while loop using increment 
Python :: python print replace old print 
Python :: ring get a list of functions names written in the Ring language 
Python :: word cloud mape python 
Python :: ring Type Hints Library user types 
Python :: vue django delimiters 
Python :: python dict setdefault list 
Python :: convert all date columns using pd.datetime 
Python :: update a variable in torch 
Python :: py3 identify file extension 
Python :: set change order python 
Python :: raise keyerror(key) from none os.environ 
Python :: python strip txt 
Python :: dataframe from function 
Python :: dbscan multidimensional data 
Python :: fibonacci numbers in lamda python 
Python :: print a commans in python 
Python :: dynamo python templete path 
Python :: pandas select rows by condition in list 
Python :: entry point not found python.exe 
Python :: alexa in python 
Python :: convert numpy array to byteslist 
Python :: python socket set title 
Python :: Select a Column in pandas data Frame Using dot notation 
Python :: python import problem fix 
Python :: How split() works when maxsplit is specified 
Python :: negative index python 
Python :: find downold dir in python 
Python :: how to get each word in a string 
Python :: python Detect Cycle in a Directed Graph 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =