top

Matplotlib中怎么设置图例的列数

在Matplotlib中,可以使用ncol参数来设置图例的列数。示例如下:

import matplotlib.pyplot as plt

# 生成数据
x = [1, 2, 3, 4, 5]
y = [1, 4, 9, 16, 25]

# 绘制折线图
plt.plot(x, y, label='y=x^2')
plt.legend(ncol=2)  # 设置图例为2列
plt.show()

在上面的示例中,plt.legend(ncol=2)设置了图例为2列。您可以根据需要调整ncol参数的值来设置图例的列数。

THE END
icon
0
icon
打赏
icon
分享
icon
二维码
icon
海报
发表评论
评论列表

赶快来坐沙发

FPS: 61