簡體   English   中英

保持一致的matplotlib軸限制

[英]maintaining consistent matplotlib axes limits

我正在嘗試制作一系列圖形,這些圖形顯示不同大小的幾何形狀(每個圖形中的一個形狀),但每個圖形上的坐標軸均等,間距一致。 我似乎無法讓matplotlib中的axis('equal')set_xlim使用。

這是我到目前為止最接近的一個:

pts0 = np.array([[13,34], [5,1], [ 0,0], [7,36], [13,34]], dtype=np.uint8)
pts1 = np.array([[10,82], [119,64], [149,63], [136,0], [82,14], [81,18], 
[26,34], [3,29], [0,34], [10,82]], dtype=np.uint8)

shapes = [pts0,pts1]
for i in range(2):
    pts = shapes[i]   
    fig = plt.figure()
    ax1 = fig.add_subplot(111)
    plotShape = patches.Polygon(pts, True, fill=True)
    p = PatchCollection([plotShape], cmap=cm.Greens)
    color = [99]
    p.set_clim([0, 100])
    p.set_array(np.array(color))
    ax1.add_collection(p)
    ax1.axis('equal')
    ax1.set_xlim(-5,200)
    ax1.set_ylim(-5,200)
    ax1.set_title('pts'+str(i))
    plt.show()

在我的系統中,這將導致兩個具有相同軸的圖形,但是它們都不顯示y = 0或形狀的下部。 如果我刪除行ax1.set_ylim(-5,200) ,則圖“ pts1”看起來正確,但是圖“ pts0”的限制使得該形狀完全不顯示。

我的理想情況是將圖形的左下角“錨定”在(-5,-5),將xlim定義為200,並允許將x軸縮放,並將ymax值縮放為“ float”,如圖所示調整了窗口的大小,但現在我很高興能始終如一地獲得圖中的形狀。

任何幫助將不勝感激!

您可以先獨立定義一個軸,然后在定義第二個軸時使用sharexsharey參數

new_ax = fig.add_axes([<bounds>], sharex=old_ax)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM