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 でグラフ表示ウィンドウの画面上の位置を自由に設定する方法

matplotlib.use(‘TkAgg’) としておき、 get_current_fig_manager().window.wm_geometry(“+20+50”) として、(+20+50)のと …

no image

matplotlib で、複数のグラフを簡単にプロットする方法

変数を並べて書くと、次のように自動的に順番を理解してグラフを表示してくれる。 例 import numpy as np from matplotlib import pyplot as plt fro …

no image

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

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

no image

matplotlib で、縦横の線(グリッド)を描く方法

pyplot grid で縦横線(罫線のようなもの)を引くことができる。 例 from matplotlib import pyplot as plt data_x = [25,26,27] …

no image

python3 で区切り文字を省略して文字列を分割する

string の split 関数は、区切り文字を指定しない場合には半角スペースや改行・タブ文字を使って自動的に分割してくれる。分割結果はリストで返される。 例 str1 = ‘Hello, nice …