Setting active subplot using axes object in matplotlib?

nbren12

The object oriented matplotlib subplots interface is nice, but I am having difficulty using it when calling a function that contains lines like plt.plot(x, y). These functions work with plt.subplot() easily, but is it possible to set the active subplot with a given axes object? Specifically I want something like the following to plot into two seperate subplots:

import matplotlib.pyplot as plt

x = [0 ,1, 2]
y= [0 ,1 2]

fig, axs = plt.subplots(2,1)

plt.some_function_to_set_active_subplot(axs[0])
plt.plot(x, y)

plt.some_function_to_set_active_subplot(axs[1])
plt.plot(x, y)

Does any such function some_function_to_set_active_subplot exist?

Edit: I specifically cannot use ax.plot, or anything like that. I am basically asking about how to mix the object oriented interface with the matlab style interface.

Edit 2: I don't want to use plt.subplot either. I want to use OO interface for setting up subplots, and matlab-style for the actual plotting.

Molly

You can use plt.axes to set the current active axes. From the documentation: "axes(h) where h is an axes instance makes h the current axis."

import matplotlib.pyplot as plt

x = [0 ,1, 2]
y = [10 ,20, 30]

fig, axs = plt.subplots(2,1)

plt.axes(axs[0])
plt.plot(x,y)
plt.axes(axs[1])
plt.plot(y,x)
plt.show()

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How are existing subplot axes retrieved using subplot2grid/gridspec in Matplotlib?

From Java

How to plot figures to different subplot axes in matplotlib

From Dev

Plot subplot axes in separate figure in matplotlib

From Dev

Matplotlib - setting tick positions on a specific subplot

From Dev

Matplotlib - setting tick positions on a specific subplot

From Dev

subplot error in Matplotlib using seaborn

From Dev

Changing matplotlib subplot size/position after axes creation

From Dev

matplotlib cancel legend on axes object

From Dev

What exactly is a matplotlib axes object?

From Dev

using fig,axes in a loop matplotlib

From Dev

how to resize figures within a subplot using matplotlib

From Dev

using a pdf image inside a subplot in matplotlib

From Dev

Arrangement of pie charts using matplotlib subplot

From Dev

Arrangement of pie charts using matplotlib subplot

From Dev

multiple graph (not subplot) using python and matplotlib

From Dev

Axes Subplot y size

From Dev

Getting data from matplotlib axes object

From Dev

What are the parameters of host_subplot in matplotlib's mpl_toolkits.axes_grid1?

From Dev

Setting the size of a matplotlib ColorbarBase object

From Dev

Setting Active worksheet using Gembox

From Dev

How to label axes in Matplotlib using LaTeX brackets?

From Dev

matplotlib: Using append_axes multiple times

From Dev

How to label axes in Matplotlib using LaTeX brackets?

From Dev

Matplotlib show parasite axes using OO API

From Dev

How to loop over the axes in a subplot

From Dev

Python - Superimpose 2 plots in subplot with matplotlib by using alpha channel

From Dev

Plotting two histograms from a pandas DataFrame in one subplot using matplotlib

From Dev

How to get the limits of plotted data from a Figure or Axes object in Matplotlib?

From Dev

matplotlib pyplot: subplot size

Related Related

  1. 1

    How are existing subplot axes retrieved using subplot2grid/gridspec in Matplotlib?

  2. 2

    How to plot figures to different subplot axes in matplotlib

  3. 3

    Plot subplot axes in separate figure in matplotlib

  4. 4

    Matplotlib - setting tick positions on a specific subplot

  5. 5

    Matplotlib - setting tick positions on a specific subplot

  6. 6

    subplot error in Matplotlib using seaborn

  7. 7

    Changing matplotlib subplot size/position after axes creation

  8. 8

    matplotlib cancel legend on axes object

  9. 9

    What exactly is a matplotlib axes object?

  10. 10

    using fig,axes in a loop matplotlib

  11. 11

    how to resize figures within a subplot using matplotlib

  12. 12

    using a pdf image inside a subplot in matplotlib

  13. 13

    Arrangement of pie charts using matplotlib subplot

  14. 14

    Arrangement of pie charts using matplotlib subplot

  15. 15

    multiple graph (not subplot) using python and matplotlib

  16. 16

    Axes Subplot y size

  17. 17

    Getting data from matplotlib axes object

  18. 18

    What are the parameters of host_subplot in matplotlib's mpl_toolkits.axes_grid1?

  19. 19

    Setting the size of a matplotlib ColorbarBase object

  20. 20

    Setting Active worksheet using Gembox

  21. 21

    How to label axes in Matplotlib using LaTeX brackets?

  22. 22

    matplotlib: Using append_axes multiple times

  23. 23

    How to label axes in Matplotlib using LaTeX brackets?

  24. 24

    Matplotlib show parasite axes using OO API

  25. 25

    How to loop over the axes in a subplot

  26. 26

    Python - Superimpose 2 plots in subplot with matplotlib by using alpha channel

  27. 27

    Plotting two histograms from a pandas DataFrame in one subplot using matplotlib

  28. 28

    How to get the limits of plotted data from a Figure or Axes object in Matplotlib?

  29. 29

    matplotlib pyplot: subplot size

HotTag

Archive