How to make a section of the axis log scale and other section to be linear scale to better present the data

huangapple go评论60阅读模式
英文:

How to make a section of the axis log scale and other section to be linear scale to better present the data

问题

我想表示我的数据,其中数值从0.00001到1,我希望在对数刻度上绘制从0.00001到0.1的数据,然后在线性刻度上绘制从0.1到0.95的数据,然后再次在对数刻度上绘制从0.95到1的数据。大部分变化发生在极端值之间,而0.1到0.9之间的数据几乎保持稳定,但我仍然需要查看它与其他数据的关系。

x轴应该像下面显示的那样。

How to make a section of the axis log scale and other section to be linear scale to better present the data

英文:

I would like to represent my data where values go from 0.00001 to 1 where I am interested in plotting data from 0.00001 to 0.1 in a log scale and from 0.1 to 0.95 in linear scale and then again 0.95 to 1 in log scale. Most of the variations happen in the extreme and the data between 0.1 to 0.9 is almost stable but i need to take a look at it though with the rest of the data.

The x axis should be like the one shown below.

How to make a section of the axis log scale and other section to be linear scale to better present the data

答案1

得分: 1

这可以通过将图分成三个部分并分配给各自的x轴来实现。这些x轴可以通过指定域(相对空间覆盖范围)放置在一起。

这是Python中的示例,但Plotly在R中应该具有相同的功能。

import plotly.graph_objects as go

x1 = [0.001, 0.01, 0.1]
x2 = [10, 100, 1000]
x3 = [1000, 10000, 100000]

y1 = [1, 2, 3]
y2 = [4, 5, 6]
y3 = [7, 8, 9]

fig = go.Figure()

fig.add_trace(go.Scatter(x=x1, y=y1, xaxis='x1'))
fig.add_trace(go.Scatter(x=x2, y=y2, xaxis='x2'))
fig.add_trace(go.Scatter(x=x3, y=y3, xaxis='x3'))

fig.update_layout(
    xaxis1=dict(
        range=[-3, 0],
        side='bottom',
        overlaying='x',
        domain=[0, 0.35],
        type='log'
    ),
    xaxis2=dict(
        range=[1, 1000],
        side='bottom',
        overlaying='x',
        domain=[0.35, 0.65],
    ),
    xaxis3=dict(
        range=[3, 6],
        side='bottom',
        overlaying='x',
        domain=[0.65, 1],
        type='log'
    ),
)

How to make a section of the axis log scale and other section to be linear scale to better present the data

英文:

This is possible by splitting the graphing in three parts and assigning each to its own x-axis. These x-axes can be placed next to each other by specifying the domain (relative coverage of space).
This is in Python, but Plotly should have the same functionality in R.

import plotly.graph_objects as go

x1 = [0.001,0.01,0.1]
x2 = [10,100,1000]
x3 = [1000,10000,100000]

y1 = [1,2,3]
y2 = [4,5,6]
y3 = [7,8,9]

fig = go.Figure()

fig.add_trace(go.Scatter(x=x1, y=y1, xaxis='x1'))
fig.add_trace(go.Scatter(x=x2, y=y2, xaxis='x2'))
fig.add_trace(go.Scatter(x=x3, y=y3, xaxis='x3'))

fig.update_layout(
    xaxis1=dict(
        range=[-3,0],
        side='bottom',
        overlaying='x',
        domain=[0,0.35],
        type='log'
        ),
    xaxis2=dict(
        range=[1,1000],
        side='bottom',
        overlaying='x',
        domain=[.35,.65],
        ),
    xaxis3=dict(
        range=[3,6],
        side='bottom',
        overlaying='x',
        domain=[.65,1],
        type='log'
        ),
    )

How to make a section of the axis log scale and other section to be linear scale to better present the data

huangapple
  • 本文由 发表于 2023年7月18日 04:27:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/76707878.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定