1
欲绘制宽度的图:高度= 1:1,并设置尺寸如何设置“纯”图形的尺寸(没有轴蜱或标题)中matplotlib
plt.figure(figsize=(10,10))
然而,它设置完整的图形的大小,包括标题和X,Y蜱。我希望“纯”图形的大小没有任何标题,x轴,y蜱是1:1。我能怎么做?谢谢!
欲绘制宽度的图:高度= 1:1,并设置尺寸如何设置“纯”图形的尺寸(没有轴蜱或标题)中matplotlib
plt.figure(figsize=(10,10))
然而,它设置完整的图形的大小,包括标题和X,Y蜱。我希望“纯”图形的大小没有任何标题,x轴,y蜱是1:1。我能怎么做?谢谢!
使用此设置应该工作:
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()
这正是我所需要的!谢谢! – wwtian