Fred Easton
Fred Easton

Reputation: 5

Python - Plotly - Indicator on top of scatter in a subplot

I'm trying to add a scatter graph to a subplot that has an indicator on it, I get following error though:

ValueError: The 'specs' argument to make_subplots must be a 2D list of dictionaries with dimensions (1 x 1). Received value of type <class 'list'>: [{'type': 'scatter'}]

Is this possible?

import numpy as np
import plotly.graph_objs as go
from plotly.subplots import make_subplots

N = 1000
t = np.linspace(0, 10, 100)
y = np.sin(t)

fig = make_subplots(
    rows=1,
    cols=1,
    specs=[{"type": "scatter"}],
    )

trace1 = go.Scatter(x=t, y=y, mode='markers')
trace2 = go.Indicator(
    domain = {'x': [0, 1], 'y': [0, 1]},
    value = 100,
    mode = "number+delta",
    title = {'text': "Current"},
    delta = {'reference': 95},
)

fig.add_trace(trace1)
fig.add_trace(trace2)
fig.show()

Upvotes: 1

Views: 680

Answers (1)

r-beginners
r-beginners

Reputation: 35230

Create two subplot settings and specify the indicator on the second one. I think that will solve the problem by overlapping the positions.

import numpy as np
import plotly.graph_objs as go
from plotly.subplots import make_subplots

N = 1000
t = np.linspace(0, 10, 100)
y = np.sin(t)

fig = make_subplots(
    rows=1,
    cols=2,
    specs=[[{"type": "scatter"},{"type": "indicator"}]])

trace1 = go.Scatter(x=t, y=y, mode='markers')
trace2 = go.Indicator(
    domain = {'x': [0, 0.7], 'y': [0, 0.25]},
    value = 100,
    mode = "number+delta",
    title = {'text': "Current"},
    delta = {'reference': 95},
)

fig.add_trace(trace1)
fig.add_trace(trace2)
fig.show()

enter image description here

Upvotes: 1

Related Questions