matplotlib设置图例项属性,如位置和handlelength through函数
以下是用于设置图例属性的示例图和函数:matplotlib设置图例项属性,如位置和handlelength through函数,matplotlib,Matplotlib,以下是用于设置图例属性的示例图和函数: import matplotlib.pyplot as plt import numpy as np fig = plt.figure() ax = fig.add_subplot(111) ax.plot(range(10), label = 'legend text') ax.plot(2 * range(10)) leg = plt.legend(title = 'legend here') def lprop_adjuster(leg, fs =
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(range(10), label = 'legend text')
ax.plot(2 * range(10))
leg = plt.legend(title = 'legend here')
def lprop_adjuster(leg, fs = 16)
ltext = leg.get_texts()
for item in ltext:
item.set_fontsize(fs)
handlelength = 4 # out of the function I would have passed it within plt.legend()
#+ but I didn't find any info about setting it in a way that can be passed
#+ through a function
lprop_adjuster(leg)
使用此方法,我可以设置标签和标题的图例字体大小(使用.get_text(),.get_title()…),在框架上或框架下设置,…,但是如何通过此函数设置位置
编辑:我还想通过该函数设置legend handlelength值。没有文档化的公共API 您可以使用未记录的私有属性,在以下位置使用友好代码更改图例:
没有文档化的公共API 您可以使用未记录的私有属性,在以下位置使用友好代码更改图例:
没有文档化的公共API 您可以使用未记录的私有属性,在以下位置使用友好代码更改图例:
没有文档化的公共API 您可以使用未记录的私有属性,在以下位置使用友好代码更改图例:
def lprop_adjuster(leg, fs=16, loc="upper right")
ltext = leg.get_texts()
for item in ltext:
item.set_fontsize(fs)
leg._loc = leg.codes[loc]