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
::  
::  
:: how to convert array of arrays into single array with unique values in numpy 
Python ::  
::  
Python :: skit learn decision 
::  
::  
::  
::  
::  
::  
Python ::  
::  
Python ::  
::  
::  
::  
::  
::  
::  
::  
::  
::  
Python ::  
:: how to run 2 async function forever 
::  
Python ::  
:: BIDS extract JSON data 
Python ::  
ADD CONTENT
Topic
Content
Source link
Name
9+5 =