8000 Reactivating `pyplot.subplot` throws warning. · Issue #12513 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
Reactivating pyplot.subplot throws warning. #12513
Closed
@ImportanceOfBeingErnest

Description

Bug report

Bug summary

Running plt.subplot after the respective subplot has already been created shows a warning. This behaviour is expected for fig.add_subplot. However in pyplot this is to my knowledge the recommended way to activate a subplot, as seen from the tutorial.

Code for reproduction

The following is the code from the second code box in the Working with multiple figures and axes section of the basic pyplot guide.

import matplotlib.pyplot as plt
plt.figure(1)                # the first figure
plt.subplot(211)             # the first subplot in the first figure
plt.plot([1, 2, 3])
plt.subplot(212)             # the second subplot in the first figure
plt.plot([4, 5, 6])


plt.figure(2)                # a second figure
plt.plot([4, 5, 6])          # creates a subplot(111) by default

plt.figure(1)                # figure 1 current; subplot(212) still current
plt.subplot(211)             # make subplot(211) in figure1 current
plt.title('Easy as 1, 2, 3') # subplot 211 title

Actual outcome

When being run it produces a warning.

MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.

Expected outcome

No warning. Using pyplot.subplot(211) should just activate the subplot, as described in the tutorial.

Alternatively, there needs to be another way to activate a subplot in pyplot (without having stored any handle to it previously).

Matplotlib version

  • Matplotlib version: 2.2.2, 3.0.0 (possibly others)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0