how to set ax.legend fontsize? [duplicate]

  • Last Update :
  • Techknowledgy :

Legend fonts are customized by providing a dict of font property-value pairs to the 'prop' kwarg:

ax.legend(prop = dict(size = 18))

Suggestion : 2

The pad between the legend handle and text. Measured in font-size units. Default is None, which will take the value from rcParams["legend.handletextpad"] = 0.8.,The pad between the axes and legend border. Measured in font-size units. Default is None, which will take the value from rcParams["legend.borderaxespad"] = 0.5.,The length of the legend handles. Measured in font-size units. Default is None, which will take the value from rcParams["legend.handlelength"] = 2.0.,The vertical space between the legend entries. Measured in font-size units. Default is None, which will take the value from rcParams["legend.labelspacing"] = 0.5.

legend()
legend(labels)
legend(handles, labels)
line, = ax.plot([1, 2, 3], label = 'Inline label')
ax.legend()
line, = ax.plot([1, 2, 3])
line.set_label('Label via method')
ax.legend()
ax.plot([1, 2, 3])
ax.legend(['A simple line'])
legend((line1, line2, line3), ('label1', 'label2', 'label3'))
loc = 'best', bbox_to_anchor = (0.5, 0., 0.5, 0.5)

Suggestion : 3

Last Updated : 22 Nov, 2021,GATE CS 2021 Syllabus

Syntax:

matplotlib.pyplot.legend( * args, ** kwargs)

For Example, 

matplotlib.pyplot.rc('lines', linewidth = 5, color = 'g')

Suggestion : 4

Updated: July 21, 2020

# Import libraries
import os
import matplotlib.pyplot as plt
import numpy as np
from shapely.geometry
import box
import geopandas as gpd
import earthpy as et

# Get the data & set working dir
data = et.data.get_data('spatial-vector-lidar')
os.chdir(os.path.join(et.io.HOME, 'earth-analytics', 'data'))
Downloading from https: //ndownloader.figshare.com/files/12459464
   Extracted output to / root / earth - analytics / data / spatial - vector - lidar / .
# Import roads shapefile
sjer_roads_path = os.path.join("spatial-vector-lidar",
   "california", "madera-county-roads",
   "tl_2013_06039_roads.shp")

sjer_roads = gpd.read_file(sjer_roads_path)

# View data type
print(type(sjer_roads['RTTYP']))
<class 'pandas.core.series.Series'>
# View unique attributes
for each road in the data
print(sjer_roads['RTTYP'].unique())
['M'
   None 'S'
   'C'
]