Reputation: 1653
so I am plotting a series of subplots using a gridspec, with all subplots having a black background. Now for bar charts, lines graphs etc. I use the following code to show a white border around the graph, and this makes all the graphs appear in their own white rectangle:
ax.spines['bottom'].set_color('w')
ax.spines['left'].set_color('w')
ax.spines['top'].set_color('w')
ax.spines['right'].set_color('w')
However for the pie chart this doesn't work and I'm presuming because a pie chart doesn't need spines. I would like to know of a way to display a white rectangle encompassing the axis object?
I was thinking perhaps a second axis in the same position with a transparent face but white spines? Or perhaps I can draw a white rectangle onto the same axis, but how?
Thanks for any help!
Upvotes: 0
Views: 885
Reputation: 13610
You can display a white box around a pie chart plot by turning on the frame.
from matplotlib.pyplot import axes, pie, show, figure, subplot
import matplotlib.gridspec as gridspec
fig = figure(facecolor = 'k')
ax1 = subplot(111, axisbg='k')
ax1.pie([1,2,3,4])
ax1.set_frame_on(True)
ax1.spines['bottom'].set_color('w')
ax1.spines['left'].set_color('w')
ax1.spines['top'].set_color('w')
ax1.spines['right'].set_color('w')
show()
Upvotes: 1