在对数刻度上绘制负值 [英] Plot negative values on a log scale

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

问题描述

我正在做一些分析来计算 log_10(x) 的值,这是一个负数.我现在试图绘制这些值,但是,由于答案的范围非常大,我想为此使用对数刻度.如果我只是使用 plt.yscale('log') 我会收到一条消息告诉我 UserWarning:数据没有正值,因此不能对数缩放. 我也无法将 x 的值提供给 plt.plot,因为 log_10(x) 的结果如此之大且为负,以至于 的答案> x **(log_10(x))就是 0 .

I am doing some analysis to calculate the value of log_10(x) which is a negative number. I am now trying to plot these values, however, since the range of the answers is very large I would like to use a logarithmic scale for this. If I simply use plt.yscale('log') I get a message telling me UserWarning: Data has no positive values, and therefore cannot be log-scaled. I also cannot supply the values of x to plt.plot as the result of log_10(x) is so large and negative that the answer of x**(log_10(x)) is simply 0.

绘制这些数据最直接的方法是什么?

What might be the most straightforward way of plotting this data?

推荐答案

您可以使用

plt.yscale('symlog')

将比例设置为对称对数比例.这意味着它将对数地缩放到0的两侧.仅使用符号对数刻度的负数部分就可以了.

to set the scale to a symmetic log scale. This means that it will scale logarithmically to both sides of 0. Only using the negative part of the symlog scale would work just fine.

这篇关于在对数刻度上绘制负值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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