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 で、os.environ で環境変数を取得する

環境変数をセットするには、ターミナルで export SOME_VAR=”hello 123″ などとして環境変数(文字列)を設定する。 プログラム(python)内で環境変数を取得するには次のように …

no image

python のプロンプトについて

UNIX で python を起動する ターミナルで $ python インタープリターのプロンプトは >>> となっている。 インタープリタを終了させるときは、Ctrl + D を押す。

no image

python3 で、csv ファイルを読み込んで条件をみたす行の内容を表示する方法

csv.reader で読み込み、各行を読み込んで判定する。 例 import csv with open(‘data.csv’, ‘r’) as csv_file: reader = csv.rea …

no image

python3 で、リストを pop したものの返り値

リストを pop すると、 pop された値が返される。 例 plant_1 = [’pumpkin’, ‘ginger’, ‘potato’] plant_2 = [] print( …

no image

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

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