Ok I see. Thanks for the codePen. It’s definitely easier to understand someone’s question with code than just words.
In particular, please note how in the first graph (top graph), Plotly has drawn the two traces beside each other when the second trace/object has its x property omitted. In this graph, the first trace has a non-numerical x axis
Hmm, there might be bug in there I was expecting your first graph to look like:
In brief, to get the desired behavior, you can simply set x: ['a', 'b', 'c', 'd']
in the second trace.
Now why does the second graph just work w/o an additional x
coordinate array? That’s because by default when x
(or y
) isn’t defined, plotly fill it in with attributes x0
and dx
where x0
(default: 0) is the starting position and dx
(default: 1) the constant step. Both x0
and dx
are ignored when x
is provided as an array. So, in your second graph that x
coords of your first trace are equivalent the linear span generated with inferred x0
and dx
of the second trace. That’s why the two trace sit on top of one another. In fact:
Plotly.plot("plot2", [
{ y: [0, 1, 2, 3], name: "name1" },
{ y: [3, 2, 1, 0], name: "name2" }
]);
gives the same result.
I guess we could build a linear span using x0
, dx
and the existing categories (in your case ['a', 'b', 'c', 'd']
) if x
isn’t provided. But, maybe that’s a little too opinionated? I feel making users enforce categories coordinates by supplying x
data for every trace is more robust API-wise.