如何创建阿拉伯图表?(X轴从右到左)带有Plotly

2024-03-29 15:17:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我想开始在x轴上从右到左绘图(对于阿拉伯图表)。所以我需要右下角的(x,y)=(0,0)。 有可能在python上用plotly实现吗?怎么做?你知道吗


Tags: 绘图图表plotly
2条回答

使用递减的x轴参数。你知道吗

import matplotlib.pyplot as plt

import numpy as np

t = np.arange(0.01, 5.0, 0.01)
s = np.exp(-t)
plt.plot(t, s)

plt.xlim(5, 0)  # decreasing time

plt.xlabel('decreasing time (s)')
plt.ylabel('voltage (mV)')
plt.title('Should be growing...')
plt.grid(True)

plt.show()

在Python中使用Plotly包:

假设我们有一个正规图(实际图,实际yaxis1 left,实际yaxis2 right,实际xaxis),我们需要将实际yaxis1 left放在右侧,将实际yaxis2 right放在左侧,并反转xaxis。 为此,我们使用以下代码:

import plotly.graph_objs as go
import plotly.offline as py

trace1=go.Bar(
                    x=[#Your years here],
                    y=[#Your data here],
                    name = 'chart1'
                )

trace2=go.Scatter(
                    x=[#your years here],
                    y=[#your data here],
                    name = 'chart2',
                    yaxis='y2'
)


data = [trace1, trace2]

layout = go.Layout(
    title="MAIN_TITLE",
    xaxis=dict(title="years",
    autorange='reversed',
    ),


    yaxis=dict(
        title='title1',
        side='right',
        showline=True
    ),


    yaxis2=dict(
        title='title2',
        side='left',
        showline=True
    )
)
fig = go.Figure(data=data, layout=layout)
py.plot(fig, filename='axes-reversed.html')

我希望这会有帮助

相关问题 更多 >