Hi,
I’m using two instances of px.imshow
as traces for display in the same plot (side by side). It seems that some properties which I assign to each of them, get ignored when they are part of the overall plot.
When I .show()
each of the two instances of px.imshow
in isolation, all of their properties take effect exactly as expected. But when I combine them into one plot via make_subplots
and add_trace
, the following attributes of interest revert to their defaults in the actual figure being displayed:
- color_continuous_scale
- labels
- (and the titles defined for the
px.imshow
subplots don’t show either, not sure I care about that detail though)
how should I be thinking about this? Is there a way to still have the axis labels and color scale defined while constructing the imshow
subplots persist when they are placed as subplots?
Here’s my code building one of the figures:
plot = px.imshow(
m,
x=[str(i) for i in range(len(input_x))],
y=[str(i) for i in range(len(input_y))],
text_auto=False,
title='foo',
color_continuous_scale=['#00aa00', '#ffff00'] if mono_colorscale else 'Viridis',
labels=dict(x='aaa', y='bbb'))
plot.update_layout(coloraxis_showscale=False)
plot.update(
data=[{'hovertemplate':
'x : %{x}<br>'
'y : %{y}<br>'
'z : %{z}<extra></extra>'}])
And I’m providing it as a trace like follows:
fig.add_trace(plot.data[0], row=1, col=1)
Whereas I’m not sure about this way of adding a trace with the data[0]
element as above, I can’t recall where I saw an example using this data[0]
attribute, I might actually suspect that this is not the standard way to nest figures as subplots into a final figure at all.
Any idea how to nest (imshow
) plots without losing the above mentioned attributes assigned to them?
I say nesting, because in some circumstances I show those imshow
instances as their own plot, and so I’m looking for an elegant code strategy that would allow them to also be reused inside a multi-figure plot without losing the visual attributes assigned to them. I’m not sure whether plotly express api is designed for such compositionality or not, and would be happy to learn of non-hacky ways of accomplishing such nesting, if the python api allows.
Thanks!