Scatter plot with infinitesimal point size in Python

∥☆過路亽.° 提交于 2019-12-08 07:33:46

问题


Is it possible to do scatter plot in python, having points have minimal size of 1 pixel at given scale? I.e. points should not scale as I scale the plot and have size of 1 pixel always.

In pyplot

plt.scatter(d3_transformed[:,0], d3_transformed[:,1], s=1)

I still get fat point like this


回答1:


You can change the marker to a point by setting marker='.', and then further reduce its size by removing the outline using linewidths=0. Note that markeredgewidth does not work with scatter.

Consider this example. As you can see, the last line of points plotted (marker='.', s=1, linewidths=0) gives the smallest markers:

import matplotlib.pyplot as plt
import numpy as np

fig, ax = plt.subplots(1)
x = np.linspace(0, 10, 100)

ax.scatter(x, np.ones_like(x)+0, marker='o', s=1, color='k')
ax.scatter(x, np.ones_like(x)+1, marker='o', s=1, color='k', linewidths=0)
ax.scatter(x, np.ones_like(x)+2, marker='.', s=1, color='k')
ax.scatter(x, np.ones_like(x)+3, marker='.', s=1, color='k', linewidths=0)

plt.show()




回答2:


In scatterplot, the points have marker which is a symbol, like circle, and this symbol has also a border. I think the border is on by default. Try to turn off the bored, like set its width to 0.

http://matplotlib.org/api/lines_api.html#matplotlib.lines.Line2D.set_markeredgewidth



来源:https://stackoverflow.com/questions/45802250/scatter-plot-with-infinitesimal-point-size-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!