I'm trying to produce a series of scatter plots with square and unfilled markers for each data point, with different but deterministic marker colors between runs, for each array. To that end, I tried using the following code:
import matplotlib.pyplot as plt
import numpy as np
x = np.array([1,2,3,4,5,6,7,8,9,10])
plt.scatter(x, x**2, s=50, marker='s',facecolors='none')
plt.scatter(x, x**3, s=50, marker='s',facecolors='none')
plt.scatter(x, x**4, s=50, marker='s',facecolors='none')
which unfills the square markers, but does not leave any marker edges, so no output is actually seen. If I instead use
plt.scatter(x, x**2, s=50, marker='s',facecolors='none',edgecolors='r')
plt.scatter(x, x**3, s=50, marker='s',facecolors='none',edgecolors='g')
plt.scatter(x, x**4, s=50, marker='s',facecolors='none',edgecolors='b')
then I do indeed see a series of data plots represented by unfilled red squares, but the downside is that I have to explicitly set what color I want using edgecolor
. However, since my actual data will consist of a variable number of arrays, with the actual number being unknown before runtime, I'm looking to plot each data series in the same scatter plot and with different colors, but without having to explicitly specify what colors to use. I could use
plt.scatter(x, y, s=50, marker='s',facecolors='none',edgecolor=np.random.rand(3,))
as I've seen answered on this SO, but this is not ideal, as I'm hoping to have deterministic colors between runs. So for example, if I have 3 arrays, then the first array to be plotted is always color 'x', the second is always color 'y' and the third is always color 'z'. Extending this to n
arrays, the nth
array plotted is also always the same color (where n
could be very large).
As an example, if we consider a simple plot using filled colors, we see that the first 3 plots are always the same color (blue, orange, green), and even when a 4th plot is added the first 3 plots retain their original colors.
3 plots, with default pyplot colors
4 plots, with the original 3 plots retaining their original colors as in the first image above
EDIT: As an aside, does anyone know the reason behind not including edgefaces
(that would then allow us to easily use default pyplot colors) when setting facecolors='none'
? It seems like a rather strange design choice.