雑多な技術系メモ

自分用のメモ。内容は保証しません。よろしくお願いします。

matplotlibについてのメモ

x軸のメモリを消す

 ax.xaxis.set_visible(False)

labelの取得

ax.get_xticklabels()

labelの設定

ax.set_xticklabels()

ticksの取得

ax.xaxis.get_xtick()

適当な間隔にする

labels = np.array(ax.get_xticklabels())
nb_step = 10
ticks = np.arange(0, len(labels), 10)
ax.xaxis.set_ticks(ticks=ticks)

marker一覧

import matplotlib.pyplot as plt
 
fig = plt.figure(figsize=(10.0, 6.0))
ax = plt.subplot(1, 2, 1)
ax.scatter(0, 0, marker=".", s=100, label=".")
ax.scatter(1, 1, marker=",", s=100, label=",")
ax.scatter(2, 2, marker="o", s=100, label="o")
ax.scatter(3, 3, marker="v", s=100, label="v")
ax.scatter(4, 4, marker="^", s=100, label="^")
ax.scatter(5, 5, marker="<", s=100, label="<")
ax.scatter(6, 6, marker=">", s=100, label=">")
ax.scatter(7, 7, marker="1", s=100, label="1")
ax.scatter(8, 8, marker="2", s=100, label="2")
ax.scatter(9, 9, marker="3", s=100, label="3")
ax.scatter(10, 10, marker="4", s=100, label="4")
ax.scatter(11, 11, marker="8", s=100, label="8")
ax.scatter(12, 12, marker="s", s=100, label="s")
ax.scatter(13, 13, marker="p", s=100, label="p")
ax.scatter(14, 14, marker="P", s=100, label="P")
ax.scatter(15, 15, marker="*", s=100, label="*")
ax.scatter(16, 16, marker="h", s=100, label="h")
ax.scatter(17, 17, marker="H", s=100, label="H")
ax.scatter(18, 18, marker="+", s=100, label="+")
ax.scatter(19, 19, marker="x", s=100, label="x")
ax.scatter(20, 20, marker="X", s=100, label="X")
ax.scatter(21, 21, marker="D", s=100, label="D")
ax.scatter(22, 22, marker="d", s=100, label="d")
ax.scatter(23, 23, marker="|", s=100, label="|")
ax.scatter(24, 24, marker="_", s=100, label="_")
 
plt.legend(bbox_to_anchor=(1.3, 1), ncol=2, loc='upper left', borderaxespad=0, fontsize=15)
plt.savefig("marker_sample.png")
plt.show()

凡例を二列に

import matplotlib.pyplot as plt
 
fig = plt.figure(figsize=(10.0, 6.0))
ax = plt.subplot(1, 2, 1)
 
ax.scatter(0, 0, marker=".", s=100, label="1")
ax.scatter(1, 1, marker=",", s=100, label="2")
ax.scatter(2, 2, marker="o", s=100, label="3")
ax.scatter(3, 3, marker="v", s=100, label="4")
plt.legend(bbox_to_anchor=(1.3, 1), ncol=2, loc='upper left', borderaxespad=0, fontsize=15)
plt.show()

グラフの全削除

plt.cla()
plt.gca().clear()