Reputation: 438
I have the following code:
import numpy as np
import matplotlib.pyplot as plt
t = np.arange(0., 5., 0.2)
plt.plot(t, t, 'r--', t, t**2, 'bs', t, t**3, 'g^')
plt.savefig('test.png')
which produces the test png:
I would like for that png to have borders (a box) around the entire plot including the labels of the axis. Could not find it in the doc.
The aimed results should look more like the following plot:
I need the exported image to have these borders. Thank you
Upvotes: 0
Views: 403
Reputation: 40667
plt.gcf().patch.set_edgecolor('k')
plt.gcf().patch.set_linewidth(3)
When saving to file though, the figure border is reverted to the value set in the rcParam 'savefig.edgecolor'
. Therefore, to get the border showing in the saved file, this parameter need to be modified:
plt.rcParams['savefig.edgecolor'] = plt.gcf().patch.get_edgecolor()
plt.savefig('test.png')
Upvotes: 1