我试图让图例适合虚线,所以我稍微使用了 rcParams,但由于某些原因它无法在我的计算机上工作。
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
matplotlib.rcParams['legend.numpoints'] = 5
matplotlib.rcParams['legend.scatterpoints'] = 5
fig, axs = plt.subplots()
axs.plot(range(10), '--k', label="line")
axs.plot(range(10), range(10)[::-1], ':k', label="scatter")
axs.legend(loc=9)
plt.show()
And the resultant figure is:
可以看出,虚线的 numpoints 是不够的。有人愿意帮忙吗?
Thanks!
如果你用标记绘制一个图,matplotlib.rcParams['legend.numpoints']
调整图例线上绘制的点数。
如果你用这些替换你的情节:
axs.plot(range(10), '--k', label="line", marker='d')
axs.plot(range(10), range(10)[::-1], ':k', label="scatter", marker='o')
you get this image:
我不知道有什么作用matplotlib.rcParams['legend.scatterpoints']
这样做,但我想调节散点图图例中的点数。
如果您想更改图例中线条的长度,请尝试matplotlib.rcParams['legend.handlelength']
and/or matplotlib.rcParams['legend.handleheight']
。有关 rc 文件的更多信息可以找到here http://matplotlib.org/users/customizing.html
正如@tcaswell 所建议的,您不必设置 rc 参数。一切legend.*
参数可作为关键字使用legend
功能。看matplotlib.pyplot.legend文档 http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.legend
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)