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

python3 で、csv ファイルの日付・数字を読み取る方法

csv をインポートすると、row in reader はリストになっている。 次のようにして、各行の要素を取り出して表示することができる。 例 import csv with open(‘data. …

no image

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

リストを iter に変えたあと、… next() を使う。 参考リンク https://www.programiz.com/python-programming/methods/buil …

no image

matplotlib で、矢印を描く方法

arrowprops のパラメータは次を参考にして設定できる。 https://matplotlib.org/stable/api/_as_gen/matplotlib.patches.FancyAr …

no image

python3 でリストを結合する方法

2つのリストを結合して、「リストのリストを作りたい場合」と、「1つの長いリストを作りたい」場合がある。 それぞれ、次のようにする。 例 # リスト2つを用意 l_1 = [1,2,3] l_2 …

no image

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

ax の xtics と ytics を使って表示する。 詳細は次のドキュメントを参照。 https://matplotlib.org/stable/gallery/lines_bars_and_ma …