pyplot - copy an axes content and show it in a new figure

后端 未结 2 883
一个人的身影
一个人的身影 2020-11-27 20:34

let say I have this code:

num_rows = 10
num_cols = 1
fig, axs = plt.subplots(num_rows, num_cols, sharex=True)
for i in xrange(num_rows):
     ax = axs[i]
            


        
2条回答
  •  眼角桃花
    2020-11-27 20:51

    If you have, for example, a plot with three lines generated by the function plot_something, you can do something like this:

    fig, axs = plot_something()
    ax = axs[2]
    l = list(ax.get_lines())[0]
    l2 = list(ax.get_lines())[1]
    l3 = list(ax.get_lines())[2]
    plot(l.get_data()[0], l.get_data()[1])
    plot(l2.get_data()[0], l2.get_data()[1])
    plot(l3.get_data()[0], l3.get_data()[1])
    ylim(0,1)
    

提交回复
热议问题