在python中绘制多行 [英] Plotting multiple lines in python

查看:116
本文介绍了在python中绘制多行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am new in Python and I want to plot multiple lines in one graph like in the figure below.

我尝试编写如下简单的绘图代码:

I have tried write simple plotting code like this:

我知道这些参数

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

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

But I have a lot of lines such in the first figure, what kind of parameters which I can use to plotting like the first figure.

谢谢

推荐答案

MPL中有许多线型和标记选项.在此处这里.

There are many options for line styles and marker in MPL. Have a look here, here and here.

对于您的特定示例(我迅速组成了一些函数并大致绘制了前几个示例):

For your specific example (I quickly made up some functions and roughly plotted the first few examples):

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

这应该给你这样的东西.

This should give you something like this.

这篇关于在python中绘制多行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆