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

Improvement in Plotting methods. #194

Merged
merged 20 commits into from Jul 20, 2018
Merged

Conversation

sushobhana
Copy link
Member

@sushobhana sushobhana commented Jun 29, 2018

added as_patch for annulus.

In [15]: reg3 = CircleAnnulusPixelRegion(PixCoord(.4,.5), .2 , .3)

In [16]: reg3.plot()
Out[16]: <matplotlib.axes._subplots.AxesSubplot at 0x7efd8f016390>

In [17]: plt.show()

new_annulus

Now, also uses visual meta data for plotting:

In [3]: st = 'image\npoint(1.3,1.5) # point=arrow 14 color=magenta'

In [4]: reg = DS9Parser(st)

In [5]: reg = reg.shapes.to_regions()[0]

In [6]: reg.plot()
Out[6]: <matplotlib.axes._subplots.AxesSubplot at 0x7fdd8e37a2e8>

In [7]: plt.show()

symbol

In [3]: st = 'image\ncircle(1.4,1.5,.3) # color=pink width=3 font="times 10 normal roman" text={Circle} tag={foo} tag={foo bar} This is a Comment'

In [4]: reg = DS9Parser(st)

In [5]: reg = reg.shapes.to_regions()[0]

In [6]: ax = reg.plot()

In [7]: ax.legend()
Out[7]: <matplotlib.legend.Legend at 0x7f7e4c1aa358>

In [8]: plt.show()

n1

In [3]: a = 'image\ntext(1315,1041) # color=magenta font="helvetica 14 bold roman" text={Region}'

In [4]: reg = DS9Parser(a).shapes.to_regions()[0]

In [5]: ax = reg.plot()

In [6]: ax.set_xlim(0,2000)
Out[6]: (0, 2000)

In [7]: ax.set_ylim(0,2000)
Out[7]: (0, 2000)

In [8]: plt.show()
/home/sushobhana/anaconda3/lib/python3.6/site-packages/matplotlib/font_manager.py:1320: UserWarning: findfont: Font family ['helvetica'] not found. Falling back to DejaVu Sans
  (prop.get_family(), self.defaultFamily[fontext]))

text1

In [7]: from regions import *

In [8]: from matplotlib import pyplot as plt

In [9]: reg3 = RectangleAnnulusPixelRegion(PixCoord(.4,.5), .2 , .3, .4, .5)

In [10]: ax =  reg3.plot()

In [11]: plt.show()

rect_new

Also, implemented the __eq__ for PixCoord.

@sushobhana sushobhana force-pushed the plotting branch 3 times, most recently from 632588c to d2c49c6 Compare July 1, 2018 21:16
@sushobhana sushobhana mentioned this pull request Jul 3, 2018
@sushobhana sushobhana force-pushed the plotting branch 3 times, most recently from d796309 to a5758e4 Compare July 11, 2018 20:08
Copy link
Contributor

@keflavich keflavich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking really good. I'm not sure I caught everything in this review; there's a lot changed here.

Could you add an example to the docs with these improved plots? Something like the images on the frontpage of the pyregion docs. That might be best as the topic of another PR, but we should show off these changes somewhere!

patch = mpatches.PathPatch(path, **kwargs)
return patch
else:
raise NotImplementedError
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this supposed to be reachable? If not, see if you can add a message that might help the user figure out what went wrong. I don't believe non-concentric annuli should be possible to declare.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it's reachable. It is the CompoundPixelRegion class and not CircleAnnulusPixelRegion

else:
self._raise_error("Not in proper format: '{0}' should be a symbol".format(y))
elif self.region_type == 'text':
self.meta['text'] = y
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we maybe use more descriptive variable names than x and y here? That might be the subject of a different PR, I just realize now looking at this code that it's hard to understand where those come from with these names.

from matplotlib.patches import Arrow
x = self.start.x
y = self.start.y
dx = self.end.x - self.start.x
dy = self.end.y - self.start.y
if not 'width' in kwargs:
kwargs['width'] = .1 # Let the default width be .1 instead of 1.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? I don't mind, just wondering if there's a reason. Does that make it look more like ds9?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not look like a line with width one. This Arrow patch seems ugly.Also, there is a line meta in DS9 decides which end of the line would be arrow like. I will work on that.

return _to_io_meta(region_meta, region_visual, valid_keys, key_mappings)
if 'font' in meta:
meta['font'] += " {0} {1} {2}".format(shape_meta.get('fontsize', 12),
shape_meta.get('fontstyle', 'normal'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whitespace (indentation isn't consistent here)

@sushobhana sushobhana force-pushed the plotting branch 2 times, most recently from a5e4460 to 6c512ae Compare July 19, 2018 20:53
@sushobhana
Copy link
Member Author

sushobhana commented Jul 19, 2018

There are a lot of big and small changes made here, and I don't want to push things further in the PR here.
There is still more to be done to make this more DS9 though.
Up for a final review!
@keflavich

@keflavich
Copy link
Contributor

I'm happy with this, so I'm merging it. Could you link to the Issues with the next steps? For one, we want a documentation page analogous to pyregion's frontpage showing all the graphical tools in action; it can pretty much be the RST version of the original issue posted here.

You also left a to-do item of having some of the internals of the plot method put into an as_patch method.

@keflavich keflavich merged commit 7dd0951 into astropy:master Jul 20, 2018
@cdeil cdeil added this to the 0.3 milestone Jun 17, 2019
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

Successfully merging this pull request may close these issues.

None yet

3 participants