How to remove subplots or create new plot from a subplot?

Hello,

Iโ€™m working with a library that generates plotly plots in some of its functions. These plots are 2x2 grids of subplots.

I am only interested in one of the subplots coming out of this function. Is there a way to delete subplots and resize the remaining subplot to use the full figure (so the title is properly centered over the subplot, for example)? Alternatively, is there a way to take a subplot and turn it into a new figure?

Iโ€™ve been searching the docs and trying to use the various methods on figures/subplots with no luck. Any help would be appreciated!

Hi @carlmarks , welcome to the forums. Sorry for the delay but maybe helpful still.

You could do something like this. Take the example form this thread:

Lets say, you are interested in the Barchart. You could select the trace and create a new figure with it:

# select the trace by index
gen_obj = fig.select_traces(selector=1)  # returns a generator object

# extract trace
trace = next(gen_obj)

# create new figure
new_fig = go.Figure(data=trace)
new_fig.show()

If you donโ€™t know the index of your trace, you can use other properties of your chart to select:

fig.select_traces(selector={'marker_color':'green'})
fig.select_traces(selector={'type':'bar'})

Keep in mind, that select_traces selects all traces if you donโ€™t specify the selector argument. You can also do something like this:

fig.select_traces(selector={'type':'scatter', 'marker_color':'blue'})

which obviously selects the scatter plot with the blue markers :wink: