python plot坐标轴显示比例一致,Matplotlib-固定x轴比例和自动缩放y轴

我以@DanHickstein的答案为基础,涵盖了plot、scatter和axhline/axvline缩放x轴或y轴的情况。它可以简单地称为autoscale()来处理最新的轴。如果你想编辑它,请fork it on gist。def autoscale(ax=None, axis='y', margin=0.1):

'''Autoscales the x or y axis of a given matplotlib ax object

to fit the margins set by manually limits of the other axis,

with margins in fraction of the width of the plot

Defaults to current axes object if not specified.

'''

import matplotlib.pyplot as plt

import numpy as np

if ax is None:

ax = plt.gca()

newlow, newhigh = np.inf, -np.inf

for artist in ax.collections + ax.lines:

x,y = get_xy(artist)

if axis == 'y':

setlim = ax.set_ylim

lim = ax.get_xlim()

fixed, dependent = x, y

else:

setlim = ax.set_xlim

lim =

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值