我想绘制宽度为:height = 1:1的图形,并将大小设置为
plt.figure(figsize=(10,10))
但是,它设置完整数字的大小,包括标题和x-,y-标记。我希望没有任何标题的“纯”数字的大小,x-,y-蜱是1:1。我能怎么做?谢谢!
答案 0 :(得分:0)
使用此设置应该有效:
plt.gca().set_aspect('equal')
例如:
它可能看起来不是正方形但它是!
import matplotlib.pyplot as plt
import numpy as np
from scipy import stats as scistats
fig = plt.figure()
A_results = np.random.poisson(50,100)
B_results = np.random.binomial(100, 0.5, (100))
slope, intercept, r_value, p_value, std_err = scistats.linregress(A_results, B_results)
plt.scatter(A_results, B_results, marker='o', color='deepskyblue', alpha=0.5, edgecolors='k', s=100, zorder=3)
plt.plot([10, 1e2], [10, 1e2], 'k-', lw=0.5, zorder=1)
plt.plot([10, 1e2], [10*slope + intercept, 1e2*slope + intercept], 'b-', lw=1.0,
label='$R^2$ = {}'.format(round(r_value**2,3)), zorder=2)
plt.xlim(10, 100)
plt.ylim(10, 100)
plt.ylabel("variate for comparison B\n(random binomial)", labelpad=15, fontweight='bold')
plt.xlabel("variate for comparison A\n(random poisson)", labelpad=15, fontweight='bold')
plt.gca().xaxis.set_tick_params(which='minor', direction='out', width=2, length=2)
plt.gca().yaxis.set_tick_params(which='minor', direction='out', width=2, length=2)
plt.gca().set_xscale('log')
plt.gca().set_yscale('log')
plt.grid(b=True, which='major', color='gray', linestyle='-', alpha=0.85, zorder=2, lw=0.5)
plt.grid(b=True, which='minor', color='gray', linestyle='-', alpha=0.65, lw=0.5)
plt.legend(loc='best', prop={'size':14})
plt.gca().set_aspect('equal')
plt.show()