I have a code which assigns a legend to each element of the datalist (17 different colors), including the same color of the errorbars.
In the process I have found very useful answers for the coloring of the plots within a loop (like in the post: Setting different color for each series in scatter plot on matplotlib) , for which I get an image like this:
The question is: how to offset each series for a dx for every iSub when having a timeseries as x axis so that the scatter plots of each iSub don't overlap?
from datetime import datetime, timedelta
import matplotlib.cm as cm
import matplotlib.dates as mdates
import matplotlib.pyplot as plt
import numpy as np
def datetime_range(start, end, delta):
current = start
while current < end:
yield current
current += delta
nSub = 17
nTimes = 34
datalist = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q']
DATA = np.random.uniform(low=0.5, high=50.0, size=(nSub,nTimes))
DZ = np.random.rand(nSub,nTimes)
timelist = [dt.strftime('%Y-%m-%d') for dt in
datetime_range(datetime(2012, 1, 1), datetime(2014, 8, 1),
timedelta(weeks=4))]
datelist = [datetime.strptime(timelist[i], '%Y-%m-%d') for i in range(len(timelist))]
fig, ax = plt.subplots (nrows=1, ncols=1)
colors = cm.rainbow(np.linspace(0, 1, len(datalist)))
for isub in range(len(datalist)):
ax.scatter(datelist, DATA[isub], label=datalist[isub], color = colors[isub])
ax.errorbar(datelist, DATA[isub], yerr = DZ[isub], color = colors[isub], fmt='o', markersize=8, capsize=20)
ax.set_xlim([datetime(2011,12,1).toordinal(), datetime(2015,1,1).toordinal()] )
ax.xaxis.set_tick_params(labelsize=20)
ax.yaxis.set_tick_params(labelsize=20)
ax.legend(loc='center left', bbox_to_anchor=(1, 0.5))
fig.set_size_inches(40,20)