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 で、軸に垂直・平行な線を書く方法

axhline, axvline を使ってx,y軸に平行な線を描くことができる。 https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot …

no image

matplotlib で、グラフ内に注釈ラベルをつける方法

annotate を使う 例 import numpy as np import matplotlib.pyplot as plt ax = plt.figure().add_subplot() th …

no image

gnuplot で、グラフの形を正方形にする方法

set size square または、その省略形で set size sq というコマンドを使えば正方形の中にグラフを描くことができる。 例 set size square plot cos(x) …

no image

python3 で、ファイルのパスから、拡張子を取り除く方法

os モジュールを使って、ファイル操作をすることができる。 ファイル名にドット. が複数の拡張子がついている場合には、拡張子を取り除く操作を何回か繰り返す。 例 import os path0 = ” …

no image

python3 で文字列を入力させて受け取る方法

C言語で scanf のようなものを作るには、python では input() で実現できる。 例 print(‘xの値を入力してください’) x = input() print(‘xの値は ‘ + …