Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

facecolor of patches by FITSFigure.show_{circles,ellipses,rectangles,polygons} is always None #84

Closed
monodera opened this issue Sep 7, 2012 · 14 comments
Milestone

Comments

@monodera
Copy link

monodera commented Sep 7, 2012

When I overlay, for example, circles on an image by using FITSFigure.show_circles() with facecolor='none' (i.e., no color), it always uses the default color set in ~/.matplotlib/matplotlirc ('blue' in my case), which probably means the function automatically change the input facecolor to facecolor=None.

I tried to fix the problem by looking at the code, and I found it works for me when I change aplpy/aplpy.py as follows.

--- aplpy.py.org    2012-09-07 18:08:40.000000000 +0200
+++ aplpy.py        2012-09-07 18:09:18.000000000 +0200
@@ -1032,9 +1032,9 @@

         patches = []
         for i in range(len(xp)):
-            patches.append(Circle((xp[i], yp[i]), radius=rp[i], **kwargs))
+            patches.append(Circle((xp[i], yp[i]), radius=rp[i]))

-        p = PatchCollection(patches, match_original=True)
+        p = PatchCollection(patches, match_original=False, **kwargs)
         if zorder is not None:
             p.zorder = zorder
         c = self._ax1.add_collection(p)

If this is right way to do, other functions, show_rectangles, show_ellipses, and show_polygons, should be fixed accordingly as I have the same problem with them. I'm still not sure this is right way for everybody, but at least works for me and want somebody else to check the issue.

@astrofrog
Copy link
Member

@mojin - this sounds like an old matplotlib bug that was later fixed. Could you do:

import matplotlib
print matplotlib.__version__

? Thanks!

@monodera
Copy link
Author

monodera commented Sep 7, 2012

>>> import matplotlib
>>> print matplotlib.__version__
1.2.x

I've installed dev version of matplotlib, which I wanted to use updated postscript implementation.

@astrofrog
Copy link
Member

Interesting - I'll look into it!

@astrofrog
Copy link
Member

@mojin - what color circle (edge and face) does the following script produce?

import matplotlib.pyplot as plt
from matplotlib.patches import Circle
from matplotlib.collections import PatchCollection

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
c = Circle((0.5, 0.5), radius=0.2, facecolor='none')
coll = PatchCollection([c], match_original=True)
ax.add_collection(coll)
fig.savefig('test.png')

@monodera
Copy link
Author

monodera commented Sep 7, 2012

This produce a circle with an edge with black line, but not filled with any color. I understand this is what you expected. There might be something wrong in my script with aplpy. Could you please give an example with aplpy?

@astrofrog
Copy link
Member

Here's an APLpy example:

import aplpy

f = aplpy.FITSFigure('2MASS_k.fits.gz')
f.show_grayscale()
f.show_circles([266.41], [-29.], [0.03], facecolor='none', edgecolor='red')
f.show_circles([266.41], [-29.], [0.06], facecolor='none', edgecolor='green')
f.show_circles([266.41], [-29.], [0.09], facecolor='none', edgecolor='blue')
f.save('test.png')

The FITS file is here and the output is:

result

Do you get the same?

@monodera
Copy link
Author

monodera commented Sep 7, 2012

I got the same result!
However, when I saved it as pdf (f.save('test.pdf')), I got strange one like this: https://www.dropbox.com/s/ap54w6nt5p53498/apltest_circle1.pdf

@astrofrog
Copy link
Member

Ah, interesting - so what do you get for

import matplotlib.pyplot as plt
from matplotlib.patches import Circle
from matplotlib.collections import PatchCollection

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
c = Circle((0.5, 0.5), radius=0.2, facecolor='none')
coll = PatchCollection([c], match_original=True)
ax.add_collection(coll)
ax.patch.set_facecolor('gray')
fig.savefig('test.pdf')

(i.e. as before, but saving as a PDF, and setting the background of the axes to gray). I have matplotlib 1.1.0 right now, so it could be an old bug that creeped back in.

@monodera
Copy link
Author

monodera commented Sep 7, 2012

https://www.dropbox.com/s/pbhiou4rir6ievq/apltest_circle2.pdf

png gives the same result.

@astrofrog
Copy link
Member

Ok, that's interesting - I'll investigate some more.

@wkerzendorf
Copy link
Contributor

Hi @astrofrog, just had the same problem.

@astrofrog
Copy link
Member

@wkerzendorf - what version of matplotlib are you using?

@wkerzendorf
Copy link
Contributor

@astrofrog oh actually a development version 1.3.x. So interestingly enough, that works:

imshow(random.random((100,100)))
circle = matplotlib.patches.Circle((50, 50), 10, facecolor='none', edgecolor='blue', linewidth=3)
ax = gca()
ax.add_patch(circle)
savefig('test.pdf')

@astrofrog
Copy link
Member

@mojin @wkerzendorf - sorry for the delay, the latest developer version of APLpy now includes a workaround (6d08bf1) for this Matplotlib bug (matplotlib/matplotlib#1860).

astrofrog added a commit to astrofrog/aplpy that referenced this issue Jul 17, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants