python - Use matplotlib Axes autoscaling without plotting anything -


matplotlib job of picking axis limits based on data throw @ it.

for example:

import matplotlib.pyplot plt import numpy np #%matplotlib inline  np.random.seed(0) y = np.random.normal(size=37, loc=2, scale=1.5) fig, (ax1, ax2) = plt.subplots(ncols=2) ax1.plot(y) ax2.plot(y * 328) fig.tight_layout() 

results in: enter image description here

both axes scaled in sane matter based on both range , order of magnitude of data.

question

how learn limits be, or apply them existing axes object without drawing on it?

ax.update_datalim seemed promising, doesn't seem hoped:

x = np.array([0] * y.shape[0]) fig, ax = plt.subplots() ax.update_datalim(list(zip(x, y)), updatex=false) 

enter image description here

i think might looking for? unsure if wanting update x-axis or not or y-axis limits without plotting.

np.random.seed(0) y = np.random.normal(size=37, loc=2, scale=1.5) fig, (ax1, ax2) = plt.subplots(ncols=2) x = np.array([0] * y.shape[0]) ax1_lim = ((0, min(y)), (len(x), max(y))) ax2_lim = ((0, min(y) * 328), (len(x), max(y) * 328)) ax1.update_datalim(ax1_lim) ax2.update_datalim(ax2_lim) ax1.autoscale() ax2.autoscale() 

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -