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 で、dictionary のキー一覧を取得する方法

dict.keys() でキーを取得することができる。 参考:dictionary の値一覧を取得するときは、dict.values() を使う。 例 print(dict.keys())

no image

python でリストに、コロン演算子2つ(::)を使う

リストのコロンで指定できるパラメータには、「start, end, step」という意味がある。 以下の例では、:: 5 とした場合には、5 をステップとして、次に進んでいく。 ::-5 とした場合に …

no image

matplotlib で、ヒストグラムを作成する方法

ヒストグラムを描くには、data_hist を使う。 ヒストグラムの縦棒の数は bins で指定する。 例 from matplotlib import pyplot as plt data_hist …

no image

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

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

no image

python3 で辞書からタプルを作成する

辞書に対して、items() メソッドを使うと、タプルを作成することができる。 例 cities = {‘東京’:1000,’大阪’:700, ‘広島’:100} for a,b in cities. …