実現したいこと
pythonを使用しています。
matplotlibを使った図に凡例をつけたいです。
python
1import matplotlib.pyplot as plt 2 3t = [0,1,2,3] 4x0 = [2,4,6,8] 5x1 = [4,6,8,10] 6x2 = [6,8,10,12]
このデータをmatplotlibで図にしたのですが、凡例がうまくつけられません。
下のようにしたいのですが、どうすればよいでしょうか。
試したこと
横に3つ並べたもの
python
1fig, (axL, axC, axR) = plt.subplots(ncols=3, figsize=(10,4)) 2axL.plot(t, x0, linewidth=2, label="X0") 3axC.plot(t, x1, linewidth=2, label="X1") 4axR.plot(t, x2, linewidth=2, label="X2") 5plt.legend()
2×2で並べたもの
python
1fig = plt.figure(figsize=(10,8)) 2axL = plt.subplot2grid((2,2), (0,0)) 3axC = plt.subplot2grid((2,2), (0,1)) 4axR = plt.subplot2grid((2,2), (1,0)) 5 6axL.plot(t, x0, linewidth=2, label="X0") 7axC.plot(t, x1, linewidth=2, label="X1") 8axR.plot(t, x2, linewidth=2, label="X2") 9plt.legend()
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。