astropy / astropy/regions

Return a Patch object in PointPixelRegion.as_artist()?

Open
#487 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
65
Forks
64
Avg merge
2d 13h
Merged PRs (30d)
4

Description

Currently the objects returned by `PointPixelRegion.as_artist()` and e.g. `CirclePixelRegion.as_artist()` are different. In one case a `Line2D` object is returned, while in the other it is a `Patch` object. This will always require an extra check when looping over or plotting multiple regions the `Line2D` plotting arguments are different than the ones for `Patch`. E.g. `facecolor` and `edgecolor` will work for `Patch`, but the corresponding argument for `Line2D` are `markeredgecolor` and `markerfacecolor` instead. So one typically ends up with code like:

```python3
for region_pix in regions_pix:

if isinstance(region, PointSkyRegion):
artist = region_pix.as_artist(**kwargs_line2d)
else:
artist = region_pix.as_artist(**kwargs)

ax.add_artist(artist)
```

I was wondering whether is is possible to unify the behavior, such that the special cases are not needed anymore. I guess what is convenient for the `Line2D` object is the ability to work with different marker styles (points, stars, triangles etc.), which would be good to keep. From a quick search it seems there is no `MarkerPatch` in `matplotlib`, which is unfortunate. @keflavich suggested to use a `PathPatch`, however this might require a lot of additional code, to achieve what `Line2D` already does. A compromise might be to maybe allow for an alias of the most common `Patch` properties, like:

```python3
ARTIST_TO_LINE_PROPERTIES = {
"color": "markeredgecolor",
"edgecolor": "markeredgecolor",
"ec": "markeredgecolor",
"facecolor": "markerfacecolor",
"fc": "markerfacecolor",
"linewidth": "markerwidth",
"lw": "markerwidth",
}
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at PointPixelRegion.as_artist() and CirclePixelRegion.as_artist(), then compare the matplotlib Line2D and Patch objects they return. Review the issue discussion to choose between a common Patch-like artist and aliases for Line2D properties; done means plotting mixed regions no longer needs special-case artist handling while preserving useful marker styles.

Written by the indexing model from the issue text.

Assessment

Tech stack
matplotlib, python
Domain
data-visualization
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.