matplotlib プロット スパインのライン スタイルを設定しようとしましたが、何らかの理由で機能しません。非表示にしたり細くしたりすることはできますが、線のスタイルを変更することはできません。
私の目的は、1 つのプロットを 2 つに分割して、外れ値を一番上に表示することです。それぞれの下/上のスパインを点線に設定して、ブレークがあることを明確に示したいと思います。
import numpy as np
import matplotlib.pyplot as plt
# Break ratio of the bottom/top plots respectively
ybreaks = [.25, .9]
figure, (ax1, ax2) = plt.subplots(
nrows=2, ncols=1,
sharex=True, figsize=(22, 10),
gridspec_kw = {'height_ratios':[1 - ybreaks[1], ybreaks[0]]}
)
d = np.random.random(100)
ax1.plot(d)
ax2.plot(d)
# Set the y axis limits
ori_ylim = ax1.get_ylim()
ax1.set_ylim(ori_ylim[1] * ybreaks[1], ori_ylim[1])
ax2.set_ylim(ori_ylim[0], ori_ylim[1] * ybreaks[0])
# Spine formatting
# ax1.spines['bottom'].set_visible(False) # This works
ax1.spines['bottom'].set_linewidth(.25) # This works
ax1.spines['bottom'].set_linestyle('dashed') # This does not work
ax2.spines['top'].set_linestyle('-') # Does not work
ax2.spines['top'].set_linewidth(.25) # Works
plt.subplots_adjust(hspace=0.05)
上記のコードは、上のプロットの下の背骨と下のプロットの上背を破線で描画することを期待しています。
何が恋しいですか?