Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python plot two lines with different y axis

import numpy as np
import matplotlib.pyplot as plt

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()
Comment

PREVIOUS NEXT
Code Example
Python :: python array colon 
Python :: how to make exe from.py file 
Python :: How to select parts of a numpy array 
Python :: connect a mean value to histogram pandas 
Python :: how to count things in a list python 
Python :: How to create role discord.py 
Python :: python 7zip extract 
Python :: django admin override save 
Python :: Python NumPy broadcast_to() Function Example 
Python :: remove space characters from string in python 
Python :: rename row pandas 
Python :: sorting a list of dictionaries 
Python :: Use module Crypto.Cipher.PKCS1_OAEP instead 
Python :: regex remove all html tags except br python 
Python :: group by, aggregate multiple column -pandas 
Python :: xticks and yticks matplotlib 
Python :: plotting roc curve 
Python :: python trim whitespace from end of string 
Python :: python cli click 
Python :: print hexadecimal in python 
Python :: pandas excel sheet name 
Python :: add metadata png PIL 
Python :: python combine two lists into matrix 
Python :: sklearn predict threshold 
Python :: strip in python 
Python :: import picturein colab 
Python :: Launching tensorboard from a python script 
Python :: python numpy array 
Python :: Read JSON files with automatic schema inference 
Python :: using a dictionary in python 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =