2013-04-14 47 views
1

繪圖時,matplotlib會自動設置被繪製的數據內容的縮放比例。但是,似乎兩個軸的限制總是等於給出的繪製數據的最大值。它使數據標記達到最大值。我想改變這種行爲,以便在標記大小的任何位置都留下一些空間。至少,有沒有辦法簡單地設置一個靜態的,用戶定義的邊距?matplotlib修改自動縮放規則

一個例子:

import matplotlib.pyplot as plt 
import matplotlib as mpl 
import numpy as np 
fig = plt.figure() 
ax = fig.add_subplot(111) 
ax.plot(np.arange(10) ** 2, 's', ms = 20) 

這個例子清楚地表明被裁剪3個數據點。

+0

可能重複[如何自動縮放Y軸在matplotlib?] (http://stackoverflow.com/questions/15375791/how-to-autoscale-y-axis-in-matplotlib) – tacaswell

回答

3

(幾乎是直接從How to autoscale y axis in matplotlib?複製)

你想marginsdoc

ax.margins(y=.1, x=.1) 

也看到了Add margin when plots run against the edge of the graph

+0

好的,其實我在開始這篇文章之前搜索了一下,但似乎我用錯誤的關鍵詞進行了搜索。這個解決方案很好,但它似乎無法獨立設置左右邊距或上下邊距。 – user1850133

+0

@ user1850133我很確定是這種情況(你不能單獨設置頂部,底部,左側,右側)。如果你真的很喜歡這個功能,那麼可以向github提交一個功能請求,或者只是手動執行軸限制。 – tacaswell

+0

我只是試圖去github,這似乎有點複雜,我會花一些時間來提交我的請求。 – user1850133