Matplotlib savefig does not save axes

前端 未结 2 1431
说谎
说谎 2021-01-13 09:39

I\'m trying to save a figure that works fine in IPython inline but does not save the figure to disk with the axes and titles included.

I am using TKAgg backend by de

2条回答
  •  执念已碎
    2021-01-13 10:31

    You are setting the axis to start at the very bottom left of the figure and to fill up the entire thing. There's no room for the axis labels or the title. Try this:

    import matplotlib.pylab as plt  
    x = [1,2,3,3]
    y = map(lambda(x): x * 2, x)
    fig = plt.figure()
    ax = fig.add_axes([0.1,0.1,0.75,0.75]) # axis starts at 0.1, 0.1
    ax.set_title("bleh")
    ax.set_xlabel("xlabel")
    ax.plot(x, y, 'r--')
    fig.savefig("fig.png")
    

    plot with axis showing

提交回复
热议问题