Matplotlib does not see the effect of setting edgecolor to plt.savefig () or plt.figure ()

I can’t figure out how to add a border around the figure, I understand that it will be the parameter figure.edgecolor or savefig (edgecolor), but this does not work. I am using matplotlib 1.1.1. I would expect this code to draw a red border around the shape:

import matplotlib.pyplot as plt plt.plot([1,2,3]) plt.savefig('test.png', edgecolor='r', facecolor='g') 

When I look at the drawing, it has a green complexion, but I do not see the red edgecolor?

The following does not work either:

 import matplotlib.pyplot as plt plt.figure(edgecolor='r', facecolor='g') plt.plot([1,2,3]) plt.show() 

Again I see a green complexion, but without a red edgecolor. What am I doing wrong?

Any ideas?

+6
source share
1 answer

According to the documentation matplotlib.figure.Figure() the linewidth edge size is set to 0.0 by default. You can visualize edgecolor if you increase this value in any of the code snippets:

 import matplotlib.pyplot as plt plt.figure(linewidth=2) plt.plot([1,2,3]) plt.savefig('test.png', edgecolor='r', facecolor='g') 

Or:

 import matplotlib.pyplot as plt plt.figure(edgecolor='r', facecolor='g', linewidth=2) plt.plot([1,2,3]) plt.show() 

linewidth=0.0 is a good default, but it should be better documented in matplotlib.pyplot.savefig () .

+6
source

Source: https://habr.com/ru/post/943921/


All Articles