Is there an easy way to add a secondary y-axis to a Plotly plot without the need of providing a second array?

Gergely Horváth

I want to have two y-axes for the same time series, an axis with the absolute number as values, and an axis with the percentages as values. Draft schematics of the desired outcome

Rob Raymond

I don't see a way of doing it without 2 traces. It does mean each trace can be switched on / off in legend so that hover gives interactivity.

import numpy as np
import pandas as pd
import plotly.graph_objects as go

x = pd.date_range("14-feb-2022", freq="1H", periods=400)
y = np.sort(np.random.pareto(2, 400))[::-1]

go.Figure(
    [
        go.Scatter(x=x, y=y, name="abs"),
        go.Scatter(
            x=x,
            y=y / y.max(),
            name="% max",
            yaxis="y2",
        ),
    ],
    layout={
        "yaxis2": {
            "side": "right",
            "tickformat": ",.0%",
        },
        "yaxis": {"overlaying": "y2"},
        "legend": {"orientation": "h", "xanchor": "center", "x": 0.5},
    },
)

enter image description here

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Add secondary y axis

Is there a way to add a second y axis to a matplotlib subplot?

Plot second y axis using plot and fill (without plotyy)

Is it possible to add another value to the plotly plot without the axis?

Plotly: Annotate using secondary y-axis

Easy way to add a break to Y-axis in barchart() of lattice in R?

Is there a way to add text to the `y2` axis of a plotly chart in R?

Align secondary percentage y axis with primary y axis in Plotly

Seaborn plot with second y axis

plotly: Is there a way to disable the right axis on adding a secondary axis?

Add second y-axis without corresponding x-data

Second Y-Axis in a R plotly graph

Plotly: How to plot a multiple y axis?

Stata: Two way plot, add text to second line using coordinates of the second axis

How to add secondary Y axis in ggplot in R?

Plotly/Dash: is it possible to hide tick labels of a secondary y axis?

Plotly: How to set a minimum value on secondary y-axis?

How to make secondary y-axis and subplots in plotly pandas?

how to enable secondary y axis in plotly & get better visuals

Adjust labels of second Y axis on the right of the plot

Is there a way to reverse the order of the y axis in heatmap of plotly

Creating a Violin Plot and Scatter Plot with a Shared Y-Axis in Plotly

Plot groupby data using secondary_y axis

Put the legend of pandas bar plot with secondary y axis in front of bars

Python making combined bar and line plot with secondary y-axis

Plot bar chart with last item in a secondary y-axis

Reverse secondary y-axis plot with ggplot2

Plot pandas columns with secondary y -axis and saving charts to a single pdf

Adding a secondary axis for another plot using scale_y_continous