# Make\_subplots extract/highlight one subplot

**URL:** <https://community.plotly.com/t/make-subplots-extract-highlight-one-subplot/74188>\
**Category:** Dash Python\
**Created:** [April 6, 2023, 1:57am UTC](https://community.plotly.com/t/make-subplots-extract-highlight-one-subplot/74188 "2023-04-06T01:57:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![marie](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/marie/32/19079_2.png) [@marie](https://community.plotly.com/u/marie)\
**Post date:** [April 6, 2023, 1:57am UTC](https://community.plotly.com/t/make-subplots-extract-highlight-one-subplot/74188/1 "2023-04-06T01:57:03Z")

</div>

We haved created a set of subplots, e.g.:

# rows, columns, and list of names populated appropirately

fig = make\_subplots(rows=rows, cols=columns, subplot\_titles=names)

and then proceed to populate them by adding traces with appropraite row and col keywords.

We would like to extract one of the subplots to use in a new figure. Construction of the plot takes a bit of time and it should be faster to extract a specific row and column from the figure data. We had hoped that the subplot would be relatively self-contained and easy to extract, but it is not obvious that this is the case. Is there a simple way to retrieve a specific subplot and bind it to a Figure that we are returning?

Thanks - Marie

---

<div class="post-metadata">

**Author:** ![AIMPED](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/aimped/32/21758_2.png) [@AIMPED](https://community.plotly.com/u/AIMPED)\
**Post date:** [April 6, 2023, 5:57am UTC](https://community.plotly.com/t/make-subplots-extract-highlight-one-subplot/74188/2 "2023-04-06T05:57:49Z")

</div>

Hi @marie, this sounds similar to this thread:

> [@How to remove subplots or create new plot from a subplot?](https://community.plotly.com/t/how-to-remove-subplots-or-create-new-plot-from-a-subplot/72117):
>
> 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…

Let us know, if it helps you.

---

<div class="post-metadata">

**Author:** ![marie](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/marie/32/19079_2.png) [@marie](https://community.plotly.com/u/marie)\
**Post date:** [April 7, 2023, 1:43pm UTC](https://community.plotly.com/t/make-subplots-extract-highlight-one-subplot/74188/3 "2023-04-07T13:43:26Z")

</div>

Thank you @AIMPED, this was helpful indeed. I ended up using an internal method on the figure, \_get\_subplot\_rows\_columns to access the geometry and then select\_traces with a specific row and column:

```auto
   def plot_subfigure(subplot, fig_subplots):
        """
        Retrieve a specific figure subplot and return it as a new figure
        :param subplot: Index of subplot 1:N
        :param fig_subplots: Figure with subplots
        :return: New figure
        """

        # Get the number of rows and columns
        row_geom, col_geom = fig_subplots._get_subplot_rows_columns()
        # Column major order, so plots per column will be our divisor
        plots_per_col = len(list(col_geom))

        # Compute row/col for referenced subplot
        subplot = subplot - 1 # 1:N --> 0:N-1
        r = int(subplot / plots_per_col) + 1
        c = subplot % plots_per_col + 1

        # select traces associated with the subplot and add them to new Fig
        traces = []
        generator = self.current_subplots[0].select_traces(row=r, col=c)
        for t in generator:
            traces.append(t)
        fig = go.Figure(data=traces)

        # Update axes - Retrieve axis information for x and y
        # then copy axis information to the new figure's axes
        for upd, get in zip([fig.update_xaxes, fig.update_yaxes],
                            [fig_subplots.select_xaxes, fig_subplots.select_yaxes]):
            ax = [a for a in get(row=r, col=c)][0]
            upd(ax) # copy properties
            # See if the subplot had a restricted viewport
            if 'domain' in ax:
                upd({'domain': (0, 1)}) # Expand to fill plot

        return fig

```

Thanks again - Marie
