Using matplotlib, I would like to plot a temperature time series so that the line color changes with temperature. For example, for a temperature range between 9 to 30 deg, the line color changes from blue (9 deg) to red (30). Any ideas and suggestions would be appreciated.
            Asked
            
        
        
            Active
            
        
            Viewed 1,989 times
        
    1 Answers
1
            You can use a scatter plot (don't use lines as they suggest values that were not measured) for this and assign colors to each point. Take this as an example:
import matplotlib.pyplot as plt
import numpy as np
t = np.linspace(0,10,10)
temperature = 21*np.sin(t)+9
colors = temperature 
plt.scatter(t,temperature,c=colors)
plt.show()
In this example I just used the temperature for colors, but you can change it, so it meets your expectations
        user8408080
        
- 2,428
 - 1
 - 10
 - 19
 
- 
                    Thanks @brainfuck4d! I think this is a good suggestion for the time series with a high resolution, as it will look like a line. I think this would also work for my high-resolution time series. :) – Behnam Nov 02 '18 at 19:11
 - 
                    1I think, if you explicitly want lines, there is also something called `LineCollection` in matplotlib; you may want to look into that. Else, please accept the answer, so others know, it's solved :) – user8408080 Nov 02 '18 at 19:16