Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

matplotlib twinx legend

import numpy as np
import matplotlib.pyplot as plt
from matplotlib import rc
rc('mathtext', default='regular')

time = np.arange(10)
temp = np.random.random(10)*30
Swdown = np.random.random(10)*100-10
Rn = np.random.random(10)*100-10

fig = plt.figure()
ax = fig.add_subplot(111)

lns1 = ax.plot(time, Swdown, '-', label = 'Swdown')
lns2 = ax.plot(time, Rn, '-', label = 'Rn')
ax2 = ax.twinx()
lns3 = ax2.plot(time, temp, '-r', label = 'temp')

# added these three lines
lns = lns1+lns2+lns3
labs = [l.get_label() for l in lns]
ax.legend(lns, labs, loc=0)

ax.grid()
ax.set_xlabel("Time (h)")
ax.set_ylabel(r"Radiation ($MJ,m^{-2},d^{-1}$)")
ax2.set_ylabel(r"Temperature ($^circ$C)")
ax2.set_ylim(0, 35)
ax.set_ylim(-20,100)
plt.show()
Comment

PREVIOUS NEXT
Code Example
Python :: generate fibonacci series in python 
Python :: fibonacci formula python 
Python :: fibonacci sequence script python 
Python :: python fibonacci sequence while loop 
Python :: python program using for for the fibonacci number 
Python :: install matplotlib on nvidia jetson nx 
Python :: pandas check if column type is list 
Python :: EMAIL_BACKEND where to read 
Python :: activate inherit function django 
Python :: Python regex emailadres no jpg 
Python :: how to make a password square multicolor square spiral python 
Python :: python date_end-date_Start in seconds 
Python :: alberi binari di ricerca python 
Python :: remove punctuation and special charaacters nltk 
Python :: mechanize python fill 
Python :: djago get settings 
Python :: pandas query return column 
Python :: multiplication objects 
Python :: get the least value from a list of dictionaries 
Python :: #check if the element exists in the list.#check if the element exists in the list. 
Python :: matplotlib get colorwheel 
Python :: how delet an obj from memori in python 
Python :: changing speak rate pyttsx 
Python :: Examples pandas.read_hfd5() 
Python :: matplotlib legend from scratch 
Python :: stop level of the broker 
Python :: plt hist random normal distribution 
Python :: How to use glob.escape() function in python 
Python :: Python NumPy broadcast_arrays() Function Syntax 
Python :: conmbination in python 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =