0

yaxis の上下に常に触れるように、matplotlib で縦の一点鎖線を取得する方法はありますか? 間にスペースを空けて 2 本の垂直線を描画しており、それらを y 軸の上部と下部に接触させたいと考えています。それらは y 軸の下部に触れますが、開始 y 値を変更すると線種パターンがたまたま上部に触れるようにすると、プロットの y 軸の上部にのみ触れます。ax.vlines も使用してみましたが、同じ結果が得られました。

たぶん - これを行うために線種のドットとダッシュの間隔を変更する方法はありますか?

plt.plot((55843.8747516981, 55843.8747516981), (yminPlot, 4.53), linewidth=2,
         linestyle='-.', color='r')
plt.plot((55843.8747516981, 55843.8747516981), (7.03, ymaxPlot), linewidth=2,
         linestyle='-.', color='r')
4

2 に答える 2

2

座標変換を使用できます (変換チュートリアル)。特定の x 座標で下から上に線を引くには:

import matplotlib.transformas as transforms

# get current axes
ax = plt.gca()

# define a blended transformation
#   ax.transData ... use data coordinates
#   ax.transAxes ... use axes coordinates ranging from (0,0) to (1,1)
trans = transforms.blended_transform_factory( ax.transData, ax.transAxes )

# plot a vertical line at x=55843.8747516981
# note that the 
plt.plot( (55843.8747516981,55843.8747516981), (0,1), linewidth=2, linestyle='-.', color='r', transform=trans)
于 2016-01-27T09:06:21.027 に答える
2

私があなたの質問を正しく理解していれば、2 番目の線の描画順序を上から下に変更することで解決できます。

plt.plot((55843.8747516981, 55843.8747516981), (yminPlot, 4.53), linewidth=2,
         linestyle='-.', color='r')
plt.plot((55843.8747516981, 55843.8747516981), (ymaxPlot, 7.03), linewidth=2,
         linestyle='-.', color='r')
于 2016-01-27T09:14:16.243 に答える