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 で、csv ファイルを読み込んで条件をみたす行の内容を表示する方法

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

no image

python3 で、フォルダがなければ作成するプログラム

os.mkdir() 関数を使う。 すでにフォルダが存在している場合は、エラーを表示する。 例 import os folder_name = ‘./python_create_folder’ try …

no image

matplotlib でエラーバーを設定する方法

pyplot.errorbar を使って設定する。 オプションの詳細は https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.erro …

no image

python3 でリストの要素を None に変更する方法

要素を None に変更すればよい。 例 arr = [1,2,3,4,5] print(str(arr)) for i in range(len(arr)): arr[i] = No …

no image

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

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