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