2013-04-24 90 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绘制,但在此之前的图像,可确保轴鳞只需要数据点。