Skip to content

Ability to add more than one canvas to a pyplot figure? #6936

@alexanderwhatley

Description

@alexanderwhatley

Is there a way to add multiple canvases corresponding to multiple axes/subplots in a single matplotlib figure? Right now, I am experimenting with interactive figures in the IPython notebook, and I would like to have this functionality, as matplotlib cannot distinguish between the individual subplots when performing dynamic updates. Say I have the code:

import matplotlib
matplotlib.use("nbagg")
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle

plt.clf()
fig1 = plt.figure("0")
axes = []
axes.append(fig1.add_subplot(1, 2, 1))
axes.append(fig1.add_subplot(1, 2, 2))
rects = [Rectangle((1,1), 5, 5, color = '0', fill = False) for i in range(2)]
axes[0].scatter([1,2,3], [4,5,6])
axes[1].scatter([1,2,6], [6,7,10])
for i in range(2):
    axes[i].add_patch(rects[i])
print(axes[0].figure.canvas)
print(axes[1].figure.canvas)

Output:

<matplotlib.backends.backend_nbagg.FigureCanvasNbAgg object at 0x000001496AA07978>
<matplotlib.backends.backend_nbagg.FigureCanvasNbAgg object at 0x000001496AA07978>

Is there a way to add two canvases; one corresponding to each of axes[0] and axes[1]? Note that I specifically want this for a single figure with multiple subplots, and not multiple figures, as I want the graphs to be on the same row.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions