第一
如
locator_params
文档:
ax.locator_params(tight=True, nbins=4)
关键字参数命名为
nbins
不
nticks
此外,您可能希望将其设置为两个轴:
ax0.locator_params(which="both", tight=True, nbins=4)
梯度方向数
不设置滴答声的数量,但设置最大箱子数,因此结果可能小于4个箱子。
ax0.axis('equal')
在设置限制后设置。您可能需要设置方面,
ax0.set_aspect('equal')
.
import matplotlib.pyplot as plt
import numpy as np
X =np.random.randn(30,2)
colors= np.random.rand(30)*5
ax0 = plt.gca()
ax0.set_aspect('equal')
cmap = plt.cm.get_cmap('RdYlBu', 9)
sc = plt.scatter(X[:, 0], X[:, 1], c=colors, vmin=0.75,
vmax=5.25, s=30, cmap=cmap)
plt.colorbar(sc, ticks=[1.0, 2.0, 3.0, 4.0, 5.0])
ax0.locator_params(which="both", tight=True, nbins=4)
ax0.set_ylim([-1.0, 1.0])
ax0.set_xlim([-1.0, 1.0])
plt.show()