fig.gca() vs. fig.add_subplot()

后端 未结 2 395
一向
一向 2020-12-29 05:39

Most examples of object-oriented matplotlib get an Axis object with something like

import matplotlib.pyplot as plt

fig1 = plt.figure()
ax1 = fig1.add_subplo         


        
相关标签:
2条回答
  • 2020-12-29 06:19

    To creat 3D instance, there are three ways:

    plt.gca(projection='3d')
    
    plt.subplot(projection='3d')
    
    fig = plt.figure()
    fig.add_subplot(111, projection='3d') 
    

    Maybe the third way is more complex.

    0 讨论(0)
  • 2020-12-29 06:28

    plt.gca gets the current axes, creating one if needed. It is only equivalent in the simplest 1 axes case.

    The preferred way is to use plt.subplots (and the docs/examples are indeed lagging a bit, if you want to start contributing, updating the docs is a great place to start):

    fig, ax = plt.subplots(1, 1)
    

    or

    fig, (ax1, ax2) = plt.subplots(2, 1)
    

    and so on.

    0 讨论(0)
提交回复
热议问题