matplotlib python3

matplotlib で目盛りに文字を使用する方法

投稿日:

文字に tex の記法を使って数式を入力することもできる。

import numpy as np
from matplotlib import pyplot as plt

x = np.linspace(-10,10,100)
y = np.sin(x)

fig, ax = plt.subplots()
ax.scatter(x,y, s=100, alpha=0.3,label="sin")

y_pos = [-1,-0.5,0.6065,1]
labels = ('minimum','-0.5',r'$\frac{1}{\sqrt{e}}$','maximum')

ax.set_yticks(y_pos)
ax.set_yticklabels(labels)

plt.show()

結果

-matplotlib, python3
-,

執筆者:


comment

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

関連記事

no image

matplotlib で、y軸に二種類の軸を設定する方法

y軸に、2種類のグラフを異なるスケールでプロットする。 matplotlib axes の twinx() を使う。 https://matplotlib.org/stable/api/_as_gen …

no image

python の __str__ と __repr__ とは

python でクラスの情報を文字列で表示するとき、__str__ メソッドと __repr__ メソッドが使える。__str__ は、プログラマーとは限らないユーザーに「読める形で情報を表示」するこ …

no image

python3 で辞書(dictionary)を削除する

clear() することによって、辞書が存在した状態のまま、キーと値をすべて削除することができる。 例 dict1 = {“名前”:”太郎”, “年齢”: 20, “住所”: “東京都千代田区大手町1 …

no image

python3 で、配列の最大値のインデックスを1つ求める方法

配列の index() メソッドを使うと、その値のインデックスを求めることができる。 最大値を求めるメソッド max と組み合わせて使う。 例 arr = [2,4,5,10,8,-3] in …

no image

matplotlib で複数のグラフを並べて表示する方法

plot.subplots() でグラフの縦方向と横方向の数を指定する。 例 import numpy as np from matplotlib import pyplot as plt x1 = …