Subplots :: The 'data' property is a tuple of trace instances

hi,

i am trying to create a line stacked subplotsā€¦ some thing like below

multiple of these types of graphs as a subplot.

below is my code:

import plotly.offline as pyo
import plotly.graph_objs as go
import pandas as pd
from plotly.tools import make_subplots

NE = pd.read_csv(ā€œC:\py\programs\plotly\final\NE.csvā€)
week_days = NE[ā€˜dateā€™].unique()
data1 =
data2 =

for day in week_days:
trace_volte_traffic = dict(type=ā€œscatterā€, x=NE[ā€œtimeā€], y=NE[NE[ā€œdateā€] == day]
[ā€œL.Traffic.User.VoIP.Avgā€], mode=ā€œlines+markersā€, name=ā€œvolte_trafficā€)
data1.append(trace_volte_traffic)

for day in week_days:
trace_PS_Traffic = dict(type=ā€œscatterā€, x=NE[ā€œtimeā€], y=NE[NE[ā€œdateā€] == day]
[ā€œLTE Traffic (DL+UL) - GBā€], mode=ā€œlines+markersā€, name=ā€œPS_trafficā€)
data2.append(trace_PS_Traffic)

fig = make_subplots(rows=2, cols=2,
horizontal_spacing=0.1,
vertical_spacing=0.1,
subplot_titles=[ā€˜Volte Trafficā€™, ā€˜PS Trafficā€™], shared_yaxes=True)

fig.append_trace(data1, 1, 1)
fig.append_trace(data2, 1, 2)

fig[ā€˜layoutā€™].update(height=1000, width=1600, title=ā€˜CS Trafficā€™)

pyo.plot(fig)

but i am getting below error

The ā€˜dataā€™ property is a tuple of trace instances
that may be specified as:
- A list or tuple of trace instances
(e.g. [Scatter(ā€¦), Bar(ā€¦)])
- A list or tuple of dicts of string/value properties where:
- The ā€˜typeā€™ property specifies the trace type
One of: [ā€˜areaā€™, ā€˜barā€™, ā€˜barpolarā€™, ā€˜boxā€™,
ā€˜candlestickā€™, ā€˜carpetā€™, ā€˜choroplethā€™, ā€˜coneā€™,
ā€˜contourā€™, ā€˜contourcarpetā€™, ā€˜heatmapā€™,
ā€˜heatmapglā€™, ā€˜histogramā€™, ā€˜histogram2dā€™,
ā€˜histogram2dcontourā€™, ā€˜mesh3dā€™, ā€˜ohlcā€™,
ā€˜parcoordsā€™, ā€˜pieā€™, ā€˜pointcloudā€™, ā€˜sankeyā€™,
ā€˜scatterā€™, ā€˜scatter3dā€™, ā€˜scattercarpetā€™,
ā€˜scattergeoā€™, ā€˜scatterglā€™, ā€˜scattermapboxā€™,
ā€˜scatterpolarā€™, ā€˜scatterpolarglā€™,
ā€˜scatterternaryā€™, ā€˜splomā€™, ā€˜streamtubeā€™,
ā€˜surfaceā€™, ā€˜tableā€™, ā€˜violinā€™]

    - All remaining properties are passed to the constructor of
      the specified trace type

    (e.g. [{'type': 'scatter', ...}, {'type': 'bar, ...}])

i am new to programming, so really thankful for your patience :slight_smile: .

Best Regards

Hi @Riz_K,

I think the problem is that the data1/data2 values that youā€™re passing to append_trace are lists of a single trace, but append_trace expects a single trace. You can either call append_trace for each trace individually, or you can use add_traces which accepts a list of traces and lists of rows and cols. In your case, I think you could do something like

fig.add_traces(data1, rows=[1]*len(data1), cols=[1]*len(data1))
fig.add_traces(data2, rows=[1]*len(data2), cols=[2]*len(data2))

In the future, please place your code in a fenced code block (https://help.github.com/articles/creating-and-highlighting-code-blocks/). This keeps the markdown renderer from messing up the formatting.

Hope that helps!

-Jon

I am really thankful for your time. it actually worked. :smiley:

Thanks again and Best Regards

1 Like