Improving the accuracy of drawing points
When drawing points with very close values, sometimes points with different values have the same meaning. In the picture below, all six points have different ordinate values, but it seems that points 2,3 and points 4,5,6 have the same value.
I know this is a permission issue (which I cannot increase for reasons not described here). However, is there any way to say matplotlib
more precisely to draw these points?
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)
source to share
The problem occurs because of the 100 dpi resolution. Since the positions of the points must be multiples of 1 pixel, their positions appear to be sampled.
You can, of course, increase the dpi while saving the image. Below is the original image, saved at 100 dpi, showing unwanted behavior.
Below is an image saved at 300 dpi and then resampled to the same size as the original image.
If you choose the size of the shape in such a way that the
figsize*saved_dpi/desired_dpi == integer
result will be even better; but then you will need to refrain from using bbox_inches='tight'
.
source to share
This is actually an algorithm problem introduced since mathlab
version 1.4. Read more here:
https://github.com/matplotlib/matplotlib/issues/8533
source to share