Matplotlib returning a plot object

前端 未结 1 1647
终归单人心
终归单人心 2020-12-13 09:53

I have a function that wraps pyplot.plt so I can quickly create graphs with oft-used defaults:

def plot_signal(time, signal, title=\'\', xlab=\'         


        
相关标签:
1条回答
  • 2020-12-13 10:20

    I think the error is pretty self-explanatory. There is no such thing as pyplot.plt, or similar. plt is the quasi standard abbreviated form of pyplot when being imported, i.e. import matplotlib.pyplot as plt.

    Concerning the problem, the first approach, return axarr is the most versatile one. You get an axes, or an array of axes, and can plot to it.

    The code may look like

    def plot_signal(x,y, ..., **kwargs):
        # Skipping a lot of other complexity her
        f, ax = plt.subplots(figsize=fig_size)
        ax.plot(x,y, ...)
        # further stuff
        return ax
    
    ax = plot_signal(x,y, ...)
    ax.plot(x2, y2, ...)
    plt.show()
    
    0 讨论(0)
提交回复
热议问题