2013-04-24 46 views

回答

2

您可以繪製在後臺imshow一個2x2的陣列。給它一個程度會使它的中心總是在0,0。

import numpy as np 
import matplotlib.pyplot as plt 

x1, y1 = np.random.randint(-8,8,5), np.random.randint(-8,8,5) 
x2, y2 = np.random.randint(-8,8,5), np.random.randint(-8,8,5) 

vmax = np.abs(np.concatenate([x1,x2,y1,y2])).max() + 5 

extent = [vmax*-1,vmax, vmax*-1,vmax] 
arr = np.array([[1,0],[0,1]]) 


fig, ax = plt.subplots(1,1) 

ax.scatter(x1,y1, marker='s', s=30, c='r', edgecolors='red', lw=1) 
ax.scatter(x2,y2, marker='s', s=30, c='none', edgecolors='red', lw=1) 

ax.autoscale(False) 
ax.imshow(arr, extent=extent, cmap=plt.cm.Greys, interpolation='none', alpha=.1) 

ax.axhline(0, color='grey') 
ax.grid(True) 

enter image description here

數據點後設置自動縮放爲False繪製,但在此之前的圖像,可確保軸鱗只需要數據點。