简体   繁体   中英

Matplotlib: how to show plot again?

Let say I make a plot in Ipython Notebook , and after couples of cells, I want to render it again, so I can compare it with other plots.

How can I do it?

a = [1,2,3,4]
b = [3,4,5,6]
fig = plt.plot(a, b,'-', color='black')

This would display the plot, but when I run fig , there is no plot output.

I find this: matplotlib show figure again , but that seems pretty complex?

UPDATE: This is what I end up with:

def simple_plot(ax = None):
    if ax is None:
        fig, ax = plt.subplots()
    a = [1,2,3,4]
    b = [3,4,5,6]
    plt.plot(a, b,'-', color='black')
    return fig

fig = simple_plot() # This would plot
fig # this would also plot

However, if I run simple_plot() , it would print twice.

You can plot like this:

a = [1,2,3,4]
b = [3,4,5,6]
f = plt.figure()
f.add_subplot(111).plot(a, b,'-', color='black')

Then render again just by calling f .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM