matplotlib- legend- ncol:图示补充文字的排版

对于:

plt.legend(label, loc=1, ncol=4)

直接看例子:

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(1, 11, 1)


label = ["First", "Second", "Third"]
plt.plot(x, x * 2)
plt.plot(x, x * 3)
plt.plot(x, x * 4)
plt.legend(label, loc=1, ncol= 2)
plt.show()

运行结果:

图示说明一列为两个,三个共排成两行


将ncol改为4:

plt.legend(label, loc=1, ncol= 4)

运行代码为:

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(1, 11, 1)


label = ["First", "Second", "Third"]
plt.plot(x, x * 2)
plt.plot(x, x * 3)
plt.plot(x, x * 4)
plt.legend(label, loc=1, ncol=4)
plt.show()

运行结果:


此时ncol = 4为一行允许放入4个参数。

猜你喜欢

转载自blog.csdn.net/lanluyug/article/details/80010243
今日推荐