2017-11-23 6 views
-1

私はPythonで新しく、下の図のように複数の行を1つのグラフにプロットしたいと思います。 enter image description herePythonで複数の行をプロットする

私は、これらのパラメータ

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

を知っている。しかし、私は、このような最初の図中の線がたくさんある、どのような:私はこのような単純なプロットコードを記述しようとしている

enter image description here

私は最初の図のようにプロットするために使用できるパラメータの種類。

ありがとうございました

答えて

1

MPLのラインスタイルとマーカーには多くのオプションがあります。見てくださいhereherehere。あなたの具体的な例

(私はすぐにいくつかの関数を作ったし、大体最初のいくつかの例をプロット):

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

これはあなたにこのような何かを与える必要があります。

enter image description here

1

あなたはその後、個別に各プロットを定義し、最初の図を定義することができます。以下は最小の例enter image description hereです。あなたはより詳細な例を見つけることができますhere(ちょうどプロットに焦点を当てる)。

import numpy as np 
import matplotlib.pyplot as plt 

t = np.linspace(1, 10, 1000) 
plt.figure(figsize=(10, 6)) 
line1, = plt.plot(t, np.sin(t * 2 * np.pi), 'b-', label='$sin(t)$') 
line2, = plt.plot(t, np.cos(t * 2 * np.pi/2), 'r--', label='$sin(t)$') 
line3, = plt.plot(t, (np.sin(t * 2 * np.pi))**2, 'k.-', label='$sin(t)$') 

plt.legend(loc='upper right') 
関連する問題