matplotlib python3

matplotlib で、x,y の軸上の数値を表示する方法

投稿日:

ax の xtics と ytics を使って表示する。

詳細は次のドキュメントを参照。

https://matplotlib.org/stable/gallery/lines_bars_and_markers/bar_label_demo.html#sphx-glr-gallery-lines-bars-and-markers-bar-label-demo-py

import numpy as np
import matplotlib
from matplotlib import pyplot as plt

x = np.linspace(-5, 5, num=100, endpoint=True)
y = np.sin(x)

fig, ax = plt.subplots()
ax.plot(x,y)

ax.set_xticks(np.arange(-3,3,1))
ax.set_yticks(np.arange(-1,1.1,0.5))

plt.show()

結果

-matplotlib, python3
-,

執筆者:


comment

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

関連記事

no image

matplotlib で、グラフのタイトルに上付き文字を入力する方法

数学記号などで、グラフのタイトルに上付きの文字を入力したい場合がある。 その場合は次のように書いて設定できる。 例 import numpy as np from matplotlib import …

no image

python3 で辞書からランダムに要素を選択する方法

items() で辞書から要素を取り出し、random.choice でランダムに要素を選択する。 例 import random # 県庁所在地 mydict = {‘宮城県’:’仙台市’,’茨城県 …

no image

python3 で集合(set)の和集合を作る

集合にモノを付け足して和集合を作るには、|= 演算子を使う。(python では、集合(set)を波かっこで囲んで表す。) 例 a = {‘東京’} b = {‘大阪’,’千葉’} c = a | b …

no image

python のプロンプトについて

UNIX で python を起動する ターミナルで $ python インタープリターのプロンプトは >>> となっている。 インタープリタを終了させるときは、Ctrl + D を押す。

no image

matplotlib で、凡例を表示する方法

データに label を関連付け、plt.legend() で凡例を表示する。 例 from matplotlib import pyplot as plt data_x = [25,26,2 …