折れ線でlinewidthを指定したい

折れ線の幅(linewidth)は、ax.plot()関数内でlinewidth引数を使って指定します。以下は修正されたコードです。

python
import matplotlib.pyplot as plt # スタイルを設定 plt.style.use('ggplot') # データを定義 x = [1, 2, 3, 4, 5] y = [2, 3, 5, 7, 11] # サブプロットを作成 fig, ax = plt.subplots() # 折れ線グラフをプロット ax.plot(x, y, marker='o', linestyle='-', color='b', label='Data', linewidth=2) # linewidthを指定 # サブプロットにタイトルと軸ラベルを追加 ax.set_title('Sample Line Plot') ax.set_xlabel('X-axis') ax.set_ylabel('Y-axis') # 凡例を表示 ax.legend() # グリッドを表示 ax.grid(True) # グラフを表示 plt.show()

このようにlinewidth引数を指定することで、折れ線の幅を変更できます。

未分類

Posted by ぼっち