How to get matplotlib for exact line placement?

By default, the matplotlib chart can place lines very inaccurately.

For example, see the placement of the left endpoint in the attached graph. There is at least a whole pixel of air that should not be. In fact, I think the center of the line is off by 2 pixels.

How to get matplotlib for accurate drawing ? I don't mind if there is any kind of performance hit.

Inaccurately displayed line in matplotlib chart:

inaccurate display line in matplotlib chart

Inaccurate line displayed in matplotlib chart - enlarged detail:

inaccurate display line in matplotlib chart - enlarged part

This was done with the default settings in Ubuntu 16.04 (Python 3), Jupyter laptop (similar result from the command line).

Mathematica, by comparison, does subpixel rendering directly and by default: Same as Mathematica Why can't we?

+4
3

, ,

import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax.plot([1, 2, 3], [4, 5, 4], clip_on=False, lw=5, alpha=.5)
ax.set_xlim([1, 3])

fig.savefig('so.png', dpi=400)

example

, snap=False plot, , , .

+2

, , . , : enter image description here

, , !

, pdf png:

enter image description here

+1

, . , plt.plot ( , ) ( Jupyter), plt.figure dpi=144 ( 72). , ...

0

Source: https://habr.com/ru/post/1652704/


All Articles