matplotlib修改自动缩放规则 [英] matplotlib modify autoscaling rules

查看:151
本文介绍了matplotlib修改自动缩放规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在绘制时,matplotlib会根据要绘制的数据内容自动设置比例.但是,似乎两个轴上的极限始终等于给定要绘制的数据中的最大值.它使达到最大值的数据标记得到了解决.我想更改此行为,以便无论标记大小如何,它都在图的四个边上留出一些空间.至少,有一种方法可以简单地设置用户定义的静态边距吗?

when plotting, matplotlib sets automatically the scales from the data content being plotted. But it seems the limits on both axes are always equal to the maxima from the data given to be plotted. It makes markers of data reaching maxima being copped. I would like to change this behaviour so that it leaves some space at the four sides of the plot whatever the marker size. At least, is there a way to simply set a static, user defined margin?

一个例子:

import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(np.arange(10) ** 2, 's', ms = 20)

此示例清楚地显示了3个数据点被裁剪.

this example clearly shows 3 data points being cropped.

推荐答案

(几乎直接从您要margins doc

ex

ax.margins(y=.1, x=.1)

另请参见添加当图靠在图的边缘时的边距

这篇关于matplotlib修改自动缩放规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆