Reputation: 29
I would like to make a scatter plot showing its time series by its color evolution (e.g., light red to dar red), where I have three independent time series data.
The current code of drawing each time series is:
trj_up = open('./up_a_2.dat','r')
lines=trj_up.readlines()
xdata = []
for i in lines:
xdata.append(float(i.split()[1]))
ydata = []
for i in lines:
ydata.append(float(i.split()[2]))
print(xdata)
print(ydata)
plt.scatter(xdata,ydata,color='blue')
Each file contains the following time series (see below). What I want to do is changing their color from 150 to 185 with color evolutions from light red to dark red, light blue to dark blue, light green to dark green.
I hope that my explanation is clear enough.
150 -29.1207268 -27.2175614
151 -30.0192526 -5.39084822
152 -26.5683873 -12.0879794
153 -23.9083554 -8.89568682
154 -24.4077309 -7.38482774
155 -30.0130369 -12.524116
156 -25.5662431 -10.7311189
157 -30.4412668 -6.75740378
158 -34.4187745 -9.34580093
159 -32.8574865 -7.13468933
160 -29.3135992 -12.6535351
161 -27.1047419 -10.032973
162 -29.9819681 -11.5874607
163 -29.5163317 -8.82843222
164 -32.4836636 -8.84216924
165 -34.8578521 -12.6671381
166 -38.7623008 -16.6893051
167 -40.6933921 -10.2265058
168 -38.6141408 -14.5406604
169 -39.4936256 -15.8318642
170 -33.2624184 -20.9177089
171 -36.4191314 -21.5573257
172 -10.0391609 -17.7451025
173 -30.9494031 -17.9689093
174 -31.5509687 -15.1635098
175 -32.2729627 -19.8517145
176 -30.5633213 -22.5465021
177 -32.3842971 -19.4456455
178 17.1779354 -21.7972776
179 15.4035048 -29.0108646
180 -7.42574637 -21.591565
181 -30.3152961 -18.2796513
182 -32.394022 -19.8493851
183 -35.4276138 -13.7519211
184 -34.5321409 -13.5833979
185 -31.9403951 -11.2472362
Upvotes: 1
Views: 1347
Reputation: 5913
scatter
takes a c
argument that can then be mapped into a colormap using the cmap
argument
https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.scatter.html
Something like ax.scatter(xdata, ydata, time, cmap='Reds')
should work, with perhaps some playing with the vmin
and vmax
arguments.
Upvotes: 0