Search code examples
plotlysubplotindicatorgauge

How to insert a Plotly Gauge (not an Indicator) as subplot?


python ver 3.8; plotly 5.3.1; dash_daq 0.5.0

There is a figure with 3 subplots: a scatter plot, an indicator and a gauge.

How to set fig's specs to insert the gauge? Or is it a gauge simply not compatible with make_subplots?

I need to insert a GAUGE, not an INDICATOR because Indicators (as for my knowledge) don't provide an "arm" as in old tachometers. The panel is read from afar and the gauge's arm is a lot more visible. (Please I don't need comments about how to change colors and so on. Only about inserting a Gauge.)

I gave a look at https://plotly.com/python/subplots/#subplots-types but didn't find any hint about a possible solution.

As a curiosity only mildly related to my question, why is it necessary to specify the plot type, when it could be automatically determined when we add each trace?

from plotly.graph_objs.scatter import Line
from plotly.subplots import make_subplots
import plotly.graph_objs as go
import dash_daq as daq

trace1 = go.Scatter(
    x = [0, 1, 2],
    y = [0, 8, 6]
)

indicator1 = go.Indicator(
    value = 6,
    mode = "gauge+number",
)

gauge1 = daq.Gauge(
    min=0,
    max=10,
    value=6
)

fig = make_subplots(rows=1, cols=3, specs=[[
    {'type':'xy'},
    {'type':'domain'},
    {'type':'domain'}]]                   # <========== ???
)

fig.append_trace(trace1, row=1, col=1)
fig.append_trace(indicator1, row=1, col=2)
# fig.append_trace(gauge1, row=1, col=3)  # <========== uncomment here!

fig.show()

Solution

  • a dash daq gauge is not a plotly trace so cannot be added to plotly figure as a trace. If you are building a dash app you can achieve through dash layout. You can add plotly indicator as traces / sub-plots to plotly, not with standing they have different capabilities