Hi @jmmease,
Thank you for the links. Unfortunately, my problem persists.
Question: Does there exist an example of āa list or tuple of dicts of string/value properties whereā the data
property is composed of at least 2 plots with at least 2 traces per plot? I think if I can just examine an example, I could get this to work but I havenāt found such an example.
To investigate this, I created a smaller data
parameter containing only 2 plots (important: each plot has 2 traces) and combined them like:
data = [tracebar, tracebox]
Here is the printed version for tracebar
(note that I created indents for easier reading):
[ { 'marker': {'color': 'blue', 'line': {'width': 1}, 'opacity': 0.6},
'name': 'Manhattan',
'type': 'bar',
'x': array([0, 1, 2]),
'y': array([ 6, 8, 18], dtype=int64)},
{ 'marker': {'color': 'orange', 'line': {'width': 1}, 'opacity': 0.5},
'name': 'Queens',
'type': 'bar',
'x': array([0, 1, 2]),
'y': array([ 3, 7, 16], dtype=int64)}]
and here is the printed version of tracebox
:
[ { 'boxpoints': 'suspectedoutliers',
'marker': { 'color': 'blue',
'line': {'outlierwidth': 1},
'opacity': 0.6,
'outliercolor': '#419ede',
'symbol': 'x'},
'name': 'Manhattan',
'type': 'box',
'x': array([0, 0, 1, 2, 2]),
'y': array([497.428 , 546. , 798.3333, 539.5714, 481.8571])},
{ 'boxpoints': 'suspectedoutliers',
'marker': { 'color': 'orange',
'line': {'outlierwidth': 1},
'opacity': 0.5,
'outliercolor': '#FFC999',
'symbol': 'x'},
'name': 'Queens',
'type': 'box',
'x': array([0, 0, 1, 2, 2]),
'y': array([712.8571, 842. , 798.333 , 420.4286, 506.1429])}]
Each trace can be successfully plotted individually (i.e. tracebox
successfully plots on its own and tracebar
successfully plots on its own). For reference, hereās the code for each:
# bar layout and plotting
layoutbar = go.Layout( title="Monthly Total: Call Quantity by Hour", barmode="group")
figbar = go.Figure(data=tracebar, layout=layoutbar)
py.plot(figbar, filename='mybar')
# box layout and plotting
layoutbox = go.Layout(yaxis=dict(type = "log", title="Travel Seconds", zeroline=True),boxmode="group"))
figbox = go.Figure(data=tracebox, layout=layoutbox)
py.plot(figbox, filename='mybox')
However, when I attempt to marry these two traces via data = [tracebar, tracebox]
, the printed version looks like this:
[ [ { 'marker': {'color': 'blue', 'line': {'width': 1}, 'opacity': 0.6},
'name': 'Manhattan',
'type': 'bar',
'x': array([0, 1, 2]),
'y': array([ 6, 8, 18], dtype=int64)},
{ 'marker': {'color': 'orange', 'line': {'width': 1}, 'opacity': 0.5},
'name': 'Queens',
'type': 'bar',
'x': array([0, 1, 2]),
'y': array([ 3, 7, 16], dtype=int64)}],
[ { 'boxpoints': 'suspectedoutliers',
'marker': { 'color': 'blue',
'line': {'outlierwidth': 1},
'opacity': 0.6,
'outliercolor': '#419ede',
'symbol': 'x'},
'name': 'Manhattan',
'type': 'box',
'x': array([0, 0, 1, 2, 2]),
'y': array([497.428 , 546. , 798.3333, 539.5714, 481.8571])},
{ 'boxpoints': 'suspectedoutliers',
'marker': { 'color': 'orange',
'line': {'outlierwidth': 1},
'opacity': 0.5,
'outliercolor': '#FFC999',
'symbol': 'x'},
'name': 'Queens',
'type': 'box',
'x': array([0, 0, 1, 2, 2]),
'y': array([712.8571, 842. , 798.333 , 420.4286, 506.1429])}]]
This looks ok to me as itās in the form outlined by the error message:
(e.g. [{'type': 'scatter', ...}, {'type': 'bar, ...}])
All remaining properties are passed to the constructor of
the specified trace type
(e.g. [{'type': 'scatter', ...}, {'type': 'bar, ...}])
Nevertheless: When I attempt to make the fig
via:
fig = go.Figure(data)
I receive the error message that indicates my data
property is incorrectly formatted.
Invalid element(s) received for the 'data' property of
Invalid elements include: [[{'type': 'bar', 'x': array([0, 1, 2]), 'y': array([ 6, 8, 18], dtype=int64), 'name': 'Manhattan', 'marker': {'color': 'blue', 'opacity': 0.6, 'line': {'width': 1}}}, {'type': 'bar', 'x': array([0, 1, 2]), 'y': array([ 3, 7, 16], dtype=int64), 'name': 'Queens', 'marker': {'color': 'orange', 'opacity': 0.5, 'line': {'width': 1}}}], [{'type': 'box', 'x': array([0, 0, 1, 2, 2]), 'y': array([497.428 , 546. , 798.3333, 539.5714, 481.8571]), 'name': 'Manhattan', 'boxpoints': 'suspectedoutliers', 'marker': {'color': 'blue', 'outliercolor': '#419ede', 'symbol': 'x', 'opacity': 0.6, 'line': {'outlierwidth': 1}}}, {'type': 'box', 'x': array([0, 0, 1, 2, 2]), 'y': array([712.8571, 842. , 798.333 , 420.4286, 506.1429]), 'name': 'Queens', 'boxpoints': 'suspectedoutliers', 'marker': {'color': 'orange', 'outliercolor': '#FFC999', 'symbol': 'x', 'opacity': 0.5, 'line': {'outlierwidth': 1}}}]]
I feel that Iām so close to making this work but my attempt to combine the two plots (each plot has 2 traces) into the data
parameter, Iām introducing an extra set of braces. I tried using go.Bar
and go.Box
versions of my plots as well but itās still not allowing me to create the figure (problem with my data
parameter).
Side: I havenāt seen a single example that uses list comprehension to create traces - are they uncommon for users because they introduce problems?