Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

matplotlib legend out of plot

ax.legend(loc='upper center', bbox_to_anchor=(0.5, 1.05),
          ncol=3, fancybox=True, shadow=True)
Comment

matplotlib legend

import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(0, 20, 1000)
y1 = np.sin(x)
y2 = np.cos(x)

plt.plot(x, y1, "-b", label="sine")
plt.plot(x, y2, "-r", label="cosine")
plt.legend(loc="upper left")
plt.ylim(-1.5, 2.0)
plt.show()
Comment

position of legend matplotlib

plt.legend(loc='upper right')
Comment

place legend on location matplotlib

import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = 6, 3
fig, axes = plt.subplots(ncols=3)
locs = ["upper left", "lower left", "center right"]
for l, ax in zip(locs, axes.flatten()):
    ax.set_title(l)
    ax.plot([1,2,3],[2,3,1], "b-", label="blue")
    ax.plot([1,2,3],[1,2,1], "r-", label="red")
    ax.legend(loc=l, bbox_to_anchor=(0.6,0.5)) # This is the key statement. 
    ax.scatter((0.6),(0.5), s=81, c="limegreen", transform=ax.transAxes)

plt.tight_layout()    
plt.show()
Comment

matplotlib position legend

plt.legend(loc='best')
plt.legend(loc='upper right')
plt.legend(loc='Center left')
plt.legend(loc='Upper center')
# etc.
Comment

legend matplotlib


import matplotlib.pyplot as plt

#define x and ysin
plt.plot(x,ysin,label='sin(x)')
plt.legend()
plt.show()
Comment

legend ax matplotlib

ax.plot([1, 2, 3], label='Inline label')
ax.legend()
Comment

matplotlib legend location manual

answer=this is how we are defining the location of legend
Comment

matplotlib legend out of plot

ax.legend(loc='upper center', bbox_to_anchor=(0.5, 1.05),
          ncol=3, fancybox=True, shadow=True)
Comment

matplotlib legend

import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(0, 20, 1000)
y1 = np.sin(x)
y2 = np.cos(x)

plt.plot(x, y1, "-b", label="sine")
plt.plot(x, y2, "-r", label="cosine")
plt.legend(loc="upper left")
plt.ylim(-1.5, 2.0)
plt.show()
Comment

position of legend matplotlib

plt.legend(loc='upper right')
Comment

place legend on location matplotlib

import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = 6, 3
fig, axes = plt.subplots(ncols=3)
locs = ["upper left", "lower left", "center right"]
for l, ax in zip(locs, axes.flatten()):
    ax.set_title(l)
    ax.plot([1,2,3],[2,3,1], "b-", label="blue")
    ax.plot([1,2,3],[1,2,1], "r-", label="red")
    ax.legend(loc=l, bbox_to_anchor=(0.6,0.5)) # This is the key statement. 
    ax.scatter((0.6),(0.5), s=81, c="limegreen", transform=ax.transAxes)

plt.tight_layout()    
plt.show()
Comment

matplotlib position legend

plt.legend(loc='best')
plt.legend(loc='upper right')
plt.legend(loc='Center left')
plt.legend(loc='Upper center')
# etc.
Comment

legend matplotlib


import matplotlib.pyplot as plt

#define x and ysin
plt.plot(x,ysin,label='sin(x)')
plt.legend()
plt.show()
Comment

legend ax matplotlib

ax.plot([1, 2, 3], label='Inline label')
ax.legend()
Comment

matplotlib legend location manual

answer=this is how we are defining the location of legend
Comment

PREVIOUS NEXT
Code Example
Python :: how to start an exe file in python 
Python :: find unique char in string python 
Python :: ping with python 
Python :: dataframe create 
Python :: onehotencoder pyspark 
Python :: df to csv 
Python :: how to install neat 
Python :: delete all elements in list python 
Python :: python update multiple dictionary values 
Python :: press key on python 
Python :: execute linux command in python 
Python :: python spotify player 
Python :: changing plot background color in python 
Python :: Python Requests Library Post Method 
Python :: how to make a stopwatch in python 
Python :: python convert object into ditct 
Python :: for i in a for j in a loop python 
Python :: sympy function definition 
Python :: shutdown flask server with request 
Python :: number of unique pairs in columns pandas 
Python :: get name of a file in python 
Python :: how to open a file with python 
Python :: STATIC_ROOT 
Python :: count dictionary keys 
Python :: python code to print prime numbers 
Python :: save image from jupyter notebook 
Python :: how to compile python 
Python :: create a blank image opencv 
Python :: count list python 
Python :: progressbar time in python 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =