I have a lot of graphs I want to plot in one plot. I've just started with matplotlib and can't find a good way to generate a lot of distinguishable colors :( Maybe cycling over HSV with SV at maximum?
I'm thinking of something like
args=[] for i,(x,y) in enumerate(data): args.extend([x,y,hsv(i)]) plot(*args)
Any suggestions? :)
Colormap. The new default colormap used by matplotlib. cm. ScalarMappable instances is 'viridis' (aka option D).
I think you have the right idea, except that the colors will be more distinguishable if you pass the colormap hsv
numbers which are spread out over the range (0,1):
hsv = plt.get_cmap('hsv') hsv(float(i)/(len(data)-1))
or, using NumPy:
colors = hsv(np.linspace(0, 1.0, len(kinds)))
For example:
import datetime as DT import numpy as np import matplotlib.pyplot as plt import matplotlib.dates as mdates import scipy.interpolate as interpolate dates = [DT.date(year, 9, 1) for year in range(2003, 2009)] t = list(map(mdates.date2num, dates)) jec = (100, 70, 125, 150, 300, 250) plt.plot(dates, jec, 'k.', markersize = 20) new_t = np.linspace(min(t), max(t), 80) new_dates = map(mdates.num2date, new_t) kinds = ('cubic', 'quadratic', 'slinear', 'nearest', 'linear', 'zero', 4, 5) cmap = plt.get_cmap('jet') colors = cmap(np.linspace(0, 1.0, len(kinds))) for kind, color in zip(kinds, colors): new_jec = interpolate.interp1d(t, jec, kind=kind)(new_t) plt.plot(new_t, new_jec, '-', label=str(kind), color=color) plt.legend(loc = 'best') plt.show()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With