天天看点

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()
           

运行结果:

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

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

将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()
           

运行结果:

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

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

继续阅读