-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Rotate Markers in functions like plot, scatter, etcetera #19195
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
I'm not sure if arbitrary markers can be rotated, but markers can take a generic ax = plt.gca()
for i, angle in enumerate(np.arange(0, 360, 60)):
ax.plot(i, i, marker=(1, 1, angle), ms=20, mew=2) |
@mwaskom no good sir, what you said is wrong, I challenge you to reproduce my image with your method... or don't waste your time and I explain you why, the tuple you used creates a regular polygon as a marker, i.e. a line (as you did) an equilateral triangle, a square, pentagon, hexagon, heptagon, etcetera... so you are not far, because if this tuple also accepted a "text" argument, them we would be set, in fact that could be a solution, add a "text" argument to this tuple, that rotates any given text as a marker. |
I don't see any reason not to add (with proper documentation and tests of course) def rotate_deg(self, rotate):
self._transform.rotate_deg(rotate) to (Also, please @Polirecyliente, lets try not to "challenge" people who are trying to help!) |
The problem in your example appeared to be placing small tick marks on a plot with arbitrary rotation. The more complicated marker is just three tick marks with the same angle and small offsets from each other. While not as simple as a single marker with a rotation parameter, that could solve your problem immediately rather than waiting on a change in matplotlib. One can also imagine writing a small function that abstracts the drawing of a triple tick mark in your code. But as you say, it seems like offering further helpful suggestions might be a waste of time... |
I think @jklymak suggestion of adding a rotation setting (and letting it come in through the attn @brunobeltran |
Is this something @brunobeltran was working on? A very quick look at Once that is all done, it seems |
Bruno has been doing a bunch of work on the |
For the sake of completion, I must say that |
Right, its the transform that is private, but passing around transforms can be problematic. But we could possibly take a transform argument when we make the marker. |
That sounds reasonable. I'd add the limitation that a passed transform should not be modified afterwards (e.g. via The API would be something like
which is a bit bulky but IMHO still ok and it lets you specify any transform you want. |
#20613 (comment) also makes the case that |
marking as a "Good First Issue". Getting the API change right is a bit tricky, but not technically difficult. It will require tests, and ideally additional documentation wherever |
I would be very happy to contribute to this feature. From the above discussion I am thinking of two implementations,
This will be my first contribution, I appreciate any help, if I have misunderstood anything or any suggestion will be great. |
Hi, sorry to interrupt, I was slowly working on this issue last couple of weeks. I was slowed down by some issues with copying/deepcopying of Path. |
Has #20914 resolved this? |
I believe so. |
Closing then, as that PR fixed it. |
Problem
Markers can't be rotated in a given angle, this would be useful even for a highschool level (I work making diagrams for a highschool level), and in general to make Matplotlib even better for making geometric diagrams.
Here is an example:
I did this diagram with Matplotlib, the code became cumbersome when trying to make the little angle markers, the ones that are two small lines perpendicular to the angle arcs. So I searched in the documentation and it seems there is no way to make marks like this builtin, there is no way to create a small perpendicular line to the arc in the middle of the arc, but then I thought about using plot markers for this.
The only problem of using markers, is that they can't be rotated, there is no way you can tell Matplotlib to make the marker perpendicular nor tangent to the line in which it's placed, or is there a way? I ask you kindly in case any of you know a way to plot markers perpendicular to the line in which they are placed.
Strangely this feature was being worked on since 2013, but it seems nothing came of it, see #2478
The way I have found to rotate markers, is using a private attribute from the markers called '_transform', this attribute has methods to rotate the marker, but it's private, this means that the API has not provided a way to access and change this attribute. Here is a minimal example to rotate the markers.
This outputs the following diagram

As can be seen, the marker is rotated 45 degrees, this marker of three small parallel lines is very common in geometric diagrams. The problem here is that I had to directly manipulate a private attribute, instead of doing that through a specific function for that purpose, such as a setter function.
Matplotlib should be capable of producing geometric diagrams, rotating markers is a basic necessity, and as I said before, I wish there could be a way to place the markers perpendicular or parallel to the line in which they are placed, so that the user wouldn't have to calculate the angle of rotation, but this isn't too bad, at least rotating the marker is necessary.
Proposed Solution
Add a wrapper function that acts as a setter for the rotation of markers. The issue #2478 probably has a better way than what I could come up with.
The text was updated successfully, but these errors were encountered: