LondonRob
LondonRob

Reputation: 78733

Save/export axes/plot area to file, not figure

There is no shortage of SO questions about saving a matplotlib figure to a file. This is easy using fig.savefig(filename).

But what if I want to save only the plot area itself, not the x- and y-axes, the outline of the plot or the title etc.

For example, I would like to export only the area shown in red below to either a .pdf or a .png: Plot area

Upvotes: 4

Views: 1382

Answers (1)

Pear666
Pear666

Reputation: 53

you can do it by simply adding the following lines in your code

plt.axis('off')
plt.savefig("test.png",bbox_inches='tight')

plt.axis('off') hides your axis and bbox_inches='tight' crops the picture of the white spaces where the axis were.

Upvotes: 1

Related Questions