matplotlib python3

matplotlib で、x軸・y軸の目盛りを反対方向につけたい場合。

投稿日:

デフォルトでは、x軸はグラフの下に、y軸は左側につけられる。

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")

ax.xaxis.set_ticks_position('top')
ax.yaxis.set_ticks_position('right')

plt.show()

結果

-matplotlib, python3
-,

執筆者:


comment

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

関連記事

no image

matplotlib で、グラフの点の見た目を変更する方法

「marker」で指定すればよい。 次のページを参考に、plotの「marker」を変更する。 https://matplotlib.org/stable/api/markers_api.html 例 …

no image

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

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

no image

pythonで配列(リスト)の、ある要素がわかっているときにその次の要素を取得する方法。

next() を使う。 例 my_arr = [‘春’,’夏’,’秋’,’冬’] my_iter = iter(my_arr) print(next(my_iter,’なし’)) print(next …

no image

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

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

no image

python3 でグローバル変数とローカル変数で同じ名前の変数を使う

グローバル変数とローカル変数で同じ名前の変数を使うことができる。 例 x = 10 def myfunc(): x = 20 print(‘関数内: x = ‘+str(x)) myfunc() pr …