在python中绘制多行

use*_*543 2 python plot linechart matplotlib plotly

我是 Python 新手,我想在一张图中绘制多条线,如下图所示。

在此处输入图片说明

我曾尝试编写这样的简单绘图代码: 在此处输入图片说明

我知道这些参数

 # red dashes, blue squares and green triangles
    plt.plot(t, t, 'r--', t, t**2, 'bs', t, t**3, 'g^')
Run Code Online (Sandbox Code Playgroud)

但是我在第一个图中有很多行,我可以使用什么样的参数来像第一个图一样绘图。

谢谢

小智 5

MPL 中的线条样式和标记有很多选项。看看这里这里这里

对于您的具体示例(我快速编写了一些函数并粗略地绘制了前几个示例):

import matplotlib.pyplot as plt
import numpy as np

x=np.arange(6)

fig=plt.figure()
fig.show()
ax=fig.add_subplot(111)

ax.plot(x,x,c='b',marker="^",ls='--',label='GNE',fillstyle='none')
ax.plot(x,x+1,c='g',marker=(8,2,0),ls='--',label='MMR')
ax.plot(x,(x+1)**2,c='k',ls='-',label='Rand')
ax.plot(x,(x-1)**2,c='r',marker="v",ls='-',label='GMC')
ax.plot(x,x**2-1,c='m',marker="o",ls='--',label='BSwap',fillstyle='none')
ax.plot(x,x-1,c='k',marker="+",ls=':',label='MSD')

plt.legend(loc=2)
plt.draw()
Run Code Online (Sandbox Code Playgroud)

这应该给你这样的东西。

在此处输入图片说明