Skip to content

Drifted marker positions #8533

Closed
Closed
@marko-pi

Description

@marko-pi

Matplotlib draws markers centered around individual pixels of the picture, which means that actual marker coordinates are approximated. This is a considerable problem when smaller resolution plots are required (e.g. creating videos). In particular, markers with slightly different coordinates are displayed on the same position.

For MWE below, all six points have different ordinate values, yet it seems as if points 2,3 and points 4,5,6 have the same value.

bad

MWE:

import matplotlib
from matplotlib import pyplot as plt

coor = [[0.5,0.525,0.55,0.575,0.6,0.625],[0.5,0.501,0.502,0.503,0.504,0.505]]

fig = plt.figure(figsize=(3.5,3.5))
plts=fig.add_subplot(1,1,1)
fig.subplots_adjust(left=0.01, right=0.99, bottom=0.01, top=0.99, hspace=0, wspace=0)

plts.set_xlim([0,1])
plts.set_ylim([0,1])
plts.get_xaxis().set_visible(False)
plts.get_yaxis().set_visible(False)

grph = plts.scatter(coor[0],coor[1],facecolor='k',marker='o',lw=0,s=25)
fig.savefig('test.png', bbox_inches='tight', dpi=100)

According to my visual experience, about two intermediate steps should be included so that the problem is no longer perceived.

The problem can be worked around by creating larger resolution plots and then downscaling them, which is sometimes a tedious process with bad side effects.

good

This problem was also reported on Stackoverflow:

http://stackoverflow.com/questions/43589568/increase-point-drawing-precision/

Best regards

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions