Strange Behavior of Python's Matplotlib Module - Plotting a Circle -
i writing program must generate set of plots. each plot must have 3 concentric circles on radii determined data set. further, red colored circle must added can have different centre. however, ran various problems. unless radius of circle/s is/are large, should see 3 black , 1 red circle on plot don't.
i isolated piece of code makes plot , here -
import matplotlib.pyplot plt fig1 = plt.figure(1, figsize=(6,6)) plt.xlim(-30,30) plt.ylim(-30,30) rcircle1 = plt.circle( (0,0), 6.0, edgecolor="black", facecolor="white") rcircle2 = plt.circle( (0,0), 12.0, edgecolor="black", facecolor="white") rcircle3 = plt.circle( (0,0), 18.0, edgecolor="black", facecolor="white") bcircle = plt.circle( (8.5,-5.8) ,2, edgecolor="red", facecolor="white") ax = fig1.gca() ax.add_artist(rcircle1) ax.add_artist(rcircle2) ax.add_artist(rcircle3) ax.add_artist(bcircle) fig1.savefig("model.png", dpi=150) the output above -

i tried looking various class variables associated circle() , add_artist() unable find might affecting behavior.
my current work around following code -
import numpy np import matplotlib.pyplot plt th = np.arange(-3.14,3.14,0.01) fig1 = plt.figure(1,figsize=(6,6)) plt.xlim(-30,30) plt.ylim(-30,30) plt.plot( 6*np.cos(th), 6*np.sin(th), color="black") plt.plot( 12*np.cos(th), 12*np.sin(th), color="black") plt.plot( 18*np.cos(th), 18*np.sin(th), color="black") # (8,5, -5,8) plt.plot( 2*np.cos(th) + 8.5, 2*np.sin(th) - 5.8, color="red") fig1.savefig("hard.png", dpi=150) the output generated above code want be!

while work, defeats purpose of having circle() methods in matplotlib. can comment why first code not working expect be?
your problem facecolor argument. you're adding biggest circle last, , has opaque center.
in second example you're plotting line, not "filled" circle.
either change order add circles in (or supply zorder kwarg), or pass in facecolor='none' (note: it's string "none", not object none) "unfilled" circle.
Comments
Post a Comment