Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Rotate Markers in functions like plot, scatter, etcetera #19195

Closed
@Polirecyliente

Description

@Polirecyliente

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:

S03_03_Angle_markings

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.

import matplotlib.pyplot as pltfrom matplotlib.markers import MarkerStylelist1 = [0, 1] #| x coordinateslist2 = [0, 0] #| y coordinatesp1 = [.5, 0] #| p1 stands for point1, the marker will be placed in this pointmarker1 = MarkerStyle(r'$|||$')marker1._transform.rotate_deg(45)plt.plot(list1, list2, 'o-k', linewidth = 1)plt.plot(p1[0], p1[1], 'k', marker = marker1)#T# show the resultsplt.show()

This outputs the following diagram
Figure_1

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp