簡體   English   中英

如何在matplotlib中設置“純”數字(沒有軸刻度或標題)的大小

[英]How to set the size of the “pure” figure (without axis ticks or title) in matplotlib

我想繪制寬度為:height = 1:1的圖形,並將大小設置為

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM