-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[ENH]: Add long names for markers #29671
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
Comments
Hi @timhoffm , I'm new to contributing to open source, but for this feature, couldn't we just invert the MarkerStyle dictionary and use the long names that already exist as keys? |
Almost. You can do diff --git a/lib/matplotlib/markers.py b/lib/matplotlib/markers.py
index 9c6b3da73b..bb5c09f99f 100644
--- a/lib/matplotlib/markers.py
+++ b/lib/matplotlib/markers.py
@@ -310,6 +310,8 @@ class MarkerStyle:
self._marker_function = self._set_mathtext_path
elif isinstance(marker, (int, str)) and marker in self.markers:
self._marker_function = getattr(self, '_set_' + self.markers[marker])
+ elif marker != "nothing" and marker in self.markers.values():
+ self._marker_function = getattr(self, '_set_' + marker)
elif (isinstance(marker, np.ndarray) and marker.ndim == 2 and
marker.shape[1] == 2):
self._marker_function = self._set_vertices which should basically do the trick. There are still some additional aspects to consider:
|
@check_figures_equal()
def test_long_name_scatter_plot(fig_ref, fig_test):
ax_ref = fig_ref.add_axes([0, 0, 1, 1])
ax_test = fig_test.add_axes([0, 0, 1, 1])
i = 0
for key, value in markers.MarkerStyle.markers.items():
if key != ',':
ax_ref.scatter([i], [1], s=50, marker=key)
ax_test.scatter([i], [1], s=50, marker=value)
i += 1
|
There are arguments for both
but we cannot have both. Unfortunately, the behavior is not even uniform throughout the library some aspects are normalized others are not. In another PR I argued for normalization due to simpler internal handling (but that's not an arguement here). I'm still on the +0 side for normalization, but can't make a strong case either way. I recommend a test. This is public API and people will rely on it. We shouldn't accidentally break it.
matplotlib/lib/matplotlib/tests/test_axes.py Line 5197 in 0b7a88a
Your solution is ok as well.
This should mostly cover it.
|
Problem
Suggested in #29646 (comment)
In addition to the single-char (and in rare cases int) marker definitions, we should also support long names
"o"
->"circle"
. These long names should be supported wherever the short mnemonics are, with the exception of thefmt
string syntax inplot()
- that should still only accept single chars.This allows more readable code
marker="tri_up"
instead ofmarker="2"
. It also opens a route for deprecating the int markers, which create trouble for parsing/validating.Proposed solution
The long names should mostly be the ones from the "description" column in https://matplotlib.org/devdocs/api/markers_api.html#module-matplotlib.markers, with some slight adjustments:
The text was updated successfully, but these errors were encountered: