0

単一の軸セットに複数のグラフをプロットしようとしています。

2D 配列のデータがあり、それを 111 個の 1D 配列に分割してプロットしたいと考えています。これまでの私のコードの例は次のとおりです。

from numpy import *
import matplotlib.pyplot as plt

x = linspace(1, 130, 130) # create a 1D array of 130 integers to set as the x axis
y = Te25117.data # set 2D array of data as y
plt.plot(x, y[1], x, y[2], x, y[3]) 

このコードは正常に動作しますが、プロット自体内でループするループを記述する方法がわかりません。毎回明示的に 1 から 111 までの数字を書いた場合にのみコードを機能させることができますが、これは理想的ではありません! (ループオーバーする必要がある数値の範囲は 1 から 111 です。)

4

2 に答える 2

3

推測させてください...長年のmatlabユーザーですか?新しいプロットを作成しない場合、Matplotlib は現在のプロットにライン プロットを自動的に追加します。したがって、コードは次のようになります。

from numpy import *
import matplotlib.pyplot as plt

x = linspace(1, 130, 130) # create a 1D array of 130 integers to set as the x axis
y = Te25117.data # set 2D array of data as y
L = len(y) # I assume you can infere the size of the data in this way...
#L = 111 # this is if you don't know any better
for i in range(L)
    plt.plot(x, y[i], color='mycolor',linewidth=1) 
于 2012-12-10T11:20:36.173 に答える
0
import numpy as np
import matplotlib.pyplot as plt
x = np.array([1,2])
y = np.array([[1,2],[3,4]])

In [5]: x
Out[5]: array([1, 2])

In [6]: y
Out[6]: 
array([[1, 2],
       [3, 4]])

In [7]: for y_i in y:
  ....:     plt.plot(x, y_i)

これらを 1 つの図にプロットします。

于 2012-12-10T11:20:44.863 に答える