对数图中的负轴 [英] Negative axis in a log plot

查看:103
本文介绍了对数图中的负轴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用matplotlib绘制对数图.我的值从1到35.

I'm plotting a log plot using matplotlib. My values go from 1 to 35.

fig=plt.figure(figsize=(7,7))
fig.subplots_adjust(top=0.75, right=0.9)
ax=fig.add_subplot(111)
ax.plot(x, y, marker='o', color='black', ls='')
ax.set_xscale('log')
ax.set_yscale('log')

我想从小于1的值开始设置x轴和y轴,但是如果我使用

I would like to set the x- and y-axis starting from values lower than 1, but if I use

ax.axis([-10,45,-10,45])

它不起作用.我知道这是因为我使用的是对数刻度,但是有没有办法解决获取我想要的轴的问题?

it doesn't work. I know that it is because I'm using a log scale, but is there a way to solve the problem obtaining the axis I want?

推荐答案

'symlog'参数用于

Use the 'symlog' argument for ax.set_xscale, as this is linear in a small interval around zero and logarithmic elsewhere.

您甚至可以使用关键字参数linthreshx(对于ax.set_yscalelinthreshy)设置希望轴为线性的间隔,该间隔接受一个元组,该元组分别包含负端和正端的限制,即linthreshx=(-linthresh,linthresh)或简单地linthreshx=linthresh.

You can even set the interval where you want the axis to be linear with the keyword argument linthreshx (linthreshy for ax.set_yscale), which accepts a tuple consisting of the limit on the negative and the positive side respectively, i.e. linthreshx=(-linthresh,linthresh), or simply linthreshx=linthresh.

ax.set_xscale('symlog')
ax.set_yscale('symlog')
ax.axis([-10,45,-10,45])

这篇关于对数图中的负轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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