I have 3-dimensional data (dtype=np.float64
) that I want to plot in a scatter plot using two of the dimensions for space and one for color, i.e. plt.scatter(data[0], data[1], c=data[2])
. I can do this and get a plot for the whole data, however, I want to create an animation of the data using portions of the entire data that was read at different times. So, if I have 1000 data points read during the first time period, I would take the first 1000 points and plot them, using c=data[2][0:1000]. Similarly, I would do this for the next timestep, and so on.
My problem occurs when I try to define a global colormap and use the entire dataset to determine the color, but I get the error, ValueError: 'c' argument has 10000 elements, which is inconsistent with 'x' and 'y' with size 1000.
How do I define a global colormap for the entirety of data[2]
, then assign colors to each point in each scatter plot from the global colormap?
I don't care about the actual colors used (they can be red-blue, green-orange, whatever). My only requirement is that the color bar be smooth.
I have tried normalizing the data with temp = plt.Normalize()
and use c = temp
in my loop, but the same error message pops up.
Here's a minimum (non)working example that throws the error:
import numpy as np
import matplotlib.pyplot as plt
totaldata = np.random.uniform(-100, 100, size=(3, 10000)) #some generated data
data = [totaldata[0][0:1000], totaldata[1][0:1000], totaldata[2][0:1000]]
plt.scatter(data[0], data[1], c=totaldata[2], cmap='viridis', s=1)
I want the colormap to be based on the entirety of the third axis of the variable totaldata
, and apply it to scatterplots of the slices of the total data.