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

python3 でランダムな整数の配列を作る方法

random モジュールを使う。randint() の引数で、配列の最小値と最大値を指定できる。 例 import random random_arr = [random.randint(-2 …

no image

matplotlib で、縦横の罫線を引く方法

破線をカスタマイズする方法 以下では、dashes = [5,2,2,2] で、線5・空白2・線2・空白2の破線を指定している。 詳しくは次を参照。 https://matplotlib.org/st …

no image

python の __str__ と __repr__ とは

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

no image

python でファイルを1行おきに読み込む方法

readline を使って次のように書く。 例 ファイル:data.txt # id name age 1 佐藤太郎 10 2 鈴木花子 18 3 坂本明美 21 4 松村光子 24 5 小川奏子 1 …

no image

python3 でコンソールからの入力をリストに格納する方法

入力を受け取るには、input() を使う。range(0,5) で、5個の文字列を順に受け取り、リストに入れてそれを表示する。 例 list1 = [] for i in range(0, …