使用matplotlib在loglog图中设置轴限制 [英] set axis limits in loglog plot with matplotlib

查看:69
本文介绍了使用matplotlib在loglog图中设置轴限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在用matplotlib绘制的点周围创建空间?

How do I create space around the points I've plotted with matplotlib?

例如,在此图中,左下角的点被轴截断,但我希望点和轴之间有更多空间.

For example, in this plot, the bottom left point is cutoff by the axis, but I would like a little more space between the point and the axis.

import matplotlib.pyplot as plt
x = [2**i for i in xrange(4,14)]
y = [i**2 for i in x]
plt.loglog(x,y,'ro',basex=2,basey=2)
plt.xlim([0, 2**14]) # <--- this line does nothing
plt.show()

在交互模式下,xlim 行返回 (16.0, 16384),旧值而不是我尝试设置的新值.

In interactive mode, the xlim line returns (16.0, 16384), the old values instead of the new values I'm trying to set.

推荐答案

不能在 loglog 图上绘制零 (log(0) = -inf).它默默地失败了,因为它不能使用 0 作为限制.

Zero can not be plotted on a loglog graph (log(0) = -inf). It is silently failing because it can not use 0 as a limit.

试试 plt.xlim([1,2**14]).

这篇关于使用matplotlib在loglog图中设置轴限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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