matplotlib python3

matplotlib で、軸に垂直・平行な線を書く方法

投稿日:

axhline, axvline を使ってx,y軸に平行な線を描くことができる。

https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.axhline.html

import math
import numpy as np
from matplotlib import pyplot as plt

x = np.linspace(-3, 3, num=100, endpoint=True)
y = np.sin(x)

fig, ax = plt.subplots()
ax.plot(x,y,'red',label='sin(x)',color='green')
ax.axhline(y=0.5,color='blue',linestyle='-.')
ax.axvline(x=0.5*math.pi,color='cyan',linestyle='--')

plt.show()

結果

-matplotlib, python3
-,

執筆者:


comment

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

関連記事

no image

python3 で、すべて小文字かどうかを判定する方法

islower() 関数を使う。 例 print(‘abcde’.islower()) print(‘abcDe’.islower()) 結果 True False

no image

matplotlib でグラフの背景の色を変える方法(facecolor)

次のように、axes で facecolor を変更すればよい。 例 from matplotlib import pyplot as plt x = [2,7,8] y = [7,1 …

no image

matplotlib で、矢印を描く方法

arrowprops のパラメータは次を参考にして設定できる。 https://matplotlib.org/stable/api/_as_gen/matplotlib.patches.FancyAr …

no image

matplotlib で、線の種類を変更する方法

「linestyle = 」として、線の種類を指定することができる設定の詳細は、次のリンクを参照。 https://matplotlib.org/stable/gallery/lines_bars_a …

no image

python の for ループで、データだけでなくインデックスも一緒に取得する

通常の for ループではなく、enumerate() を使うとインデックスが取得できる。 例 list1 = [’太郎’,’次郎’,’三郎’] for i, name in enumerat …