outside legends example python matplotlib font-size legend

python - legends - Cómo establecer el tamaño de fuente del eje Matplotlib Leyenda?



matplotlib show legends (6)

Tengo un código como este:

import matplotlib.pyplot as plt from matplotlib.pyplot import * from matplotlib.font_manager import FontProperties fontP = FontProperties() fontP.set_size(''xx-small'') fig=plt.figure() ax1=fig.add_subplot(111) plot([1,2,3], label="test1") ax1.legend(loc=0, ncol=1, bbox_to_anchor=(0, 0, 1, 1), prop = fontP,fancybox=True,shadow=False,title=''LEGEND'') plt.show()

Se puede ver en la trama que la configuración en Fontsize no afecta el tamaño de fuente del Título de la leyenda.

¿Cómo establecer el tamaño de la fuente del título de la leyenda en un tamaño más pequeño?


Aquí se muestra cómo cambiar el tamaño de fuente de la lista de leyendas y / o el título de la leyenda:

legend=plt.legend(list,loc=(1.05,0.05), title=r''$/bf{Title}$'') #Legend: list, location, Title (in bold) legend.get_title().set_fontsize(''6'') #legend ''Title'' fontsize plt.setp(plt.gca().get_legend().get_texts(), fontsize=''12'') #legend ''list'' fontsize


Esta es definitivamente una vieja pregunta, pero también me estaba frustrando y ninguna de las otras respuestas cambió el título de la leyenda, pero cambió el resto del texto. Así que después de golpear mi cabeza contra la documentación matplotlib por un tiempo, se me ocurrió esto.

legend = ax1.legend(loc=0, ncol=1, bbox_to_anchor=(0, 0, 1, 1), prop = fontP,fancybox=True,shadow=False,title=''LEGEND'') plt.setp(legend.get_title(),fontsize=''xx-small'')


Este es el más rápido:

plt.legend(loc=2,prop={''size'':6})


Generalmente lo hago de esta manera. Una vez que se ha hecho la trama, hago lo siguiente

plt.legend(loc=0, numpoints=1) leg = plt.gca().get_legend() ltext = leg.get_texts() plt.setp(ltext, fontsize=''small'')

No sé si esto funciona para ti


Golpeé mi cabeza contra eso también, aquí hay otra forma más fluida de hacerlo:

leg = ax.legend() leg.set_title(''A great legend'',prop={''size'':14})


No sé cómo configurarlo para una trama individual, pero siempre lo hago a nivel mundial:

plt.rc(''legend'',**{''fontsize'':6})