0

I was trying to plot some points as single pixels in my mollweide projection when I realized that the points got automatically connected by lines made of the same kind of marker. (see image below) My final application is plotting stars in the sky, given ICRS coordinates.

I found ways to avoid this problem using plt.scatter (see below with squared markers) or using healpy, but is it possible to plot the points with plt.plot without being connected by lines? Here is an simple example code and its output:

from matplotlib import pyplot as plt
import numpy as np
fig = plt.figure()
plt.subplot(111, projection="mollweide")
x = np.array([-np.radians(120), 0, np.radians(120)])
y = np.array([0, np.radians(30), 0])
plt.plot(x, y, ',')
plt.scatter(x, y, marker=',')
plt.grid(), plt.show()
fig.savefig('example.png')

output:

mollweide projections of my points

EDIT: where I used plt.scatter() to show a possible workaround (the marker would then have to be personalized).

note that plt.plot(x,y,',') behave as desired when no projection is used as show in the following plot:
reference plot without projection
(where I plotted the red circles to show the small plotted blue pixels that plt.plot() plotted as desired).

I want to achieve it with plt.plot() as it should be faster for this kind of task: The plot function will be faster for scatterplots where markers don't vary in size or color. said on the documentation page of scatter(here)

EDIT_2: It is not a duplicate since setting linestyle='None' as suggested in the suggested question does not resolve the problem what so ever. This is probably since thoses "lines" are not real lines but markers plotted in between the points acting as virtual lines.

Community
  • 1
  • 1
alaka
  • 13
  • 4
  • But you have `plt.plot(x, y, ',')` in your code. Remove this, and it doesn't connect the markers that you plot with `plt.scatter(x, y, marker=',')`. – Mr. T Nov 23 '18 at 16:47
  • As Mr. T said: calling `plot()` is superfluous. I'd expect `plt.plot(x, y, ':')` to show a dotted line as seen in your example, `,` should not connect the points with a line. See [here](https://matplotlib.org/api/markers_api.html) and [here](https://matplotlib.org/gallery/lines_bars_and_markers/line_styles_reference.html) for marker and line style options respectively. – normanius Nov 23 '18 at 16:54
  • @Mr.T, sorry for the ambiguity: I plotted the squares with `plt.scatter()` just to show that it would be a possible workaround, but I wanted to know if it is possible to do with `plt.plot()` as `plt.plot(x,y,',')` should in theory just plot the points and not connect them together. I though it could be useful as it is said in the documentation that for this task `plt.plot` should be faster as said [here](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.scatter.html) : _The plot function will be faster for scatterplots where markers don't vary in size or color._ – alaka Nov 23 '18 at 17:31

0 Answers0