【发布时间】:2017-09-18 17:13:58
【问题描述】:
我正在绘制一个包含六条曲线的图表,其中每条曲线都有一个标签。图例位于图形下方,但比图形宽。请看代码和截图。
#!/usr/bin/python
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(10)
fig = plt.figure()
ax = plt.subplot(111)
for i in xrange(6):
ax.plot(x, i * x, label='long_long_name = %ix$' % i)
#ax.legend()
ax.legend(loc='upper center', bbox_to_anchor=(0.5, -0.05),
fancybox=True, shadow=True, ncol=3)
fig.tight_layout(rect=[0, 0.1, 1, 0.95])
plt.show()
如何配置正确的图表和图例大小/位置? 我查看了Legend Guide 和this post,但无法弄清楚如何使图例变窄。
【问题讨论】:
-
为什么不直接指定
ncol=2? -
实际上效果很好。谢谢
标签: python matplotlib