10000 Custom marker created from vertex list scales wrong · Issue #1980 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
Custom marker created from vertex list scales wrong #1980
Closed
@vMeijin

Description

@vMeijin

Hello,
I am new here and I dont know if this is the right place, but I found a slight misbehave, when creating a custom markerstyle. If you plot something, eg:

pyplot.plot([0,0], [1,1], markersize=5, marker=[[0,0], [0,1], [1, 1], [1,0]) # marker is a square with size 1

The marker has the same size as marker='s', but is not centered. If you use

pyplot.plot([0,0], [1,1], markersize=5, marker=[[-0.5,-0.5], [-0.5,0.5], [0.5,0.5]], [0.5,-0.5]) # still square of size 1

the resulting marker is centered but twice the size. The problem is the the function MarkerStyle._set_custom_marker in markers.py:

def _set_custom_marker(self, path):
    verts = path.vertices
    rescale = max(np.max(np.abs(verts[:,0])), np.max(np.abs(verts[:,1])))
    self._transform = Affine2D().scale(1.0 / rescale)
    self._path = path

It rescales the given vertices, but considers only the max xy values, which results in twice. the size A solution could be to change the rescale factor to:

x, y = verts[:,0], verts[:,1]
rescale = max(abs(np.max(x) - np.min(x)), abs(np.max(y) - np.min(y)))

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0