pyplot.axesでグラフを表示する際に、縦横比を1:1に揃えたい場合。
axes.set_aspect('equal')
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
import numpy as np import matplotlib.pyplot as plt num_points = 50 x = np.zeros(num_points) y = np.zeros(num_points) for n in range(0, 50): x[n] = np.random.rand() y[n] = np.random.rand() fig = plt.figure() ax1 = fig.add_subplot(211) ax2 = fig.add_subplot(212) ax1.grid(True) ax2.grid(True) ax2.set_aspect('equal') ax1.scatter(x, y) ax2.scatter(x, y) plt.show() |