2016-08-19 22 views

回答

0

使用此設置應該工作:

plt.gca().set_aspect('equal') 

例如:

enter image description here

它可能不看多,但它是!

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() 
+0

這正是我所需要的!謝謝! – wwtian