とプロットをスライスした後、私は10から次に20matplotlibののオートスケール(軸= 'Y')set_xlim()デモンストレーションとして
の範囲のX値とX^9を介してX^0をプロットしていI私は私の画像がそのようにyの値をトリミングしたい
(18〜19)に
X =(10〜11)、(11〜12)等:「私は9つのスライスを有するようにこれらの画像をスライスm個常に各スライスの上から下に広がっていますが、私が得ているのは、現在のスライスではなく、オートスケールが常にフルデータセットにスケールすることです。
import matplotlib.pyplot as plt
import numpy as np
# create some test data
for i in range(10):
x = np.arange(10,20)
y = x**i
plt.plot(x,y,c='red',marker='.',ms=2)
# get all x values in chart and reduce to a sorted list set
xd = []
for n in range(len(plt.gca().get_lines())):
line = plt.gca().get_lines()[n]
xd.append((line.get_xdata()).tolist())
xd = [item for sublist in xd for item in sublist]
xd = sorted(list(set(xd)))
# attempt to plot slices of x with autoscaled y
ax = plt.gca()
for i in range(len(xd)-1):
ax.set_xlim([xd[i],xd[i+1]])
ax.axes.autoscale(enable=True,axis='y', tight=True)
plt.pause(1) #timing
#uncommenting the next line will create nine tiny (6kb) image files
#plt.savefig(('image_%s.png' % i), bbox_inches=0, dpi=48)
私の実際のアプリケーションでは、この方法で100kの小さな画像を確率的データから生成しようとしています。すべてのxについて、2〜200のy値がある。次に、OpenCVを使用して、履歴データベースの中に最適なイメージに新しいイメージをマッチングさせます。
OpenCVの各画像でy値が上から下に伸びて、良い一致が見つかることが重要です。
それは私のxの値は、常に(int型になります場合に役立ちます)を入力し、等間隔
ETA:私はここに解決策の一部を実装しようとしましたが、何の進展なされていない:
Matplotlib - fixing x axis scale and autoscale y axis
をMatplotlib scale y axis based on manually zoomed x axis
が、少なくとも私は学んだ:
自動スケーリングは常にデータの全範囲を使用するため、y軸は x-limitsの範囲だけでなく、yデータの全範囲でスケーリングされた です。私は、実装がどこか不明だけど、それらのリンクから
h = np.max(y_displayed) - np.min(y_displayed) ValueError: zero-size array to reduction operation maximum which has no identity
@:ここで働く
まだ解決策は@DanHickstein
が提示し
def autoscale_y()
かかわらず、私を与えません私のforループのJoe Kingtonのマスクソリューション。
How to extract points from a graph?
多分、私は手動でXの最小値と最大Y値を与えられた)(set_ylimことができます。
私は今@bernie溶液で働いているが与えられたYの値がX得るためにここで提案しましたか?標準matplotlibの方法Iは、Xキーなどのとyのそれぞれのリストと辞書を作成することで、最後の夜、私の問題を解決し