Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

center fig legend

import numpy as np
import matplotlib.pyplot as plt

fig, (ax1, ax2) = plt.subplots(nrows=2, sharex=True)

x = np.linspace(0, np.pi, 100)

line1, = ax1.plot(x, np.cos(3*x), color='red')
line2, = ax2.plot(x, np.sin(4*x), color='green')

# The key to the position is bbox_to_anchor: Place it at x=0.5, y=0.5
# in figure coordinates.
# "center" is basically saying center horizontal alignment and 
# center vertical alignment in this case
fig.legend([line1, line2], ['yep', 'nope'], bbox_to_anchor=[0.5, 0.5], 
           loc='center', ncol=2)

plt.show()
Comment

PREVIOUS NEXT
Code Example
Python :: parse tree tags 
Python :: Python logging comma to dot 
Python :: nlp generate parse tree in python 
Python :: check if there is a certain number difference with python 
Python :: python project pick text color according to background 
Python :: cartpole dqn reward max is 200 
Python :: mhaan meaning in english 
Python :: pandas read csv skip until expression found 
Python :: generator expressions python 
Python :: python how to request query string korean encode 
Python :: call for a last number in series python 
Python :: can i register a list in python for input 
Python :: ipywidgets unobserve functools partial 
Python :: python how to get variable value in dict 
Python :: bar chart with x-ticks 
Python :: combine int and object columns into one 
Python :: map dataframe parallel 
Python :: python fibonacci sequence 
Python :: pylatex subsection 
Python :: python selenium for desktop application 
Python :: concatenar columnas en una del mismo dataset 
Python :: python time.sleep slow 
Python :: mechanize python #6 
Python :: comment interpreter tuple python avec valeur unique 
Python :: get_multiple_items_from_list 
Python :: remove duplicate rows in pandas 
Python :: fill variable based on values of other variables python 
Python :: Pandas number of columns display settings 
Python :: pyttsx3 listen to events 
Python :: Code Example of Comparing None with None type 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =