python - Changing axis on scatterplot to fixed intervals involving time -
i have following code. problem want set range of y axis 0:00 12:00 , have equally spaced in increments of one. e.g. 0:00, 1:00, 2:00 etc. suggestions how go doing this?
also want rid of :00 @ end of each number. of right reads 00:00:00, 01:00:00 , on when want read 0:00, 1:00 ideas how can go doing this? here code have far.
import pandas pd import matplotlib.pyplot plt import datetime data = pd.read_csv('data.csv', sep=',', header=none) print (data) ints = data[data[1]=='int'] exts = data[data[1]=='ext'] int_times = [datetime.datetime.time(datetime.datetime.strptime(t, '%h:%m')) t in ints[4]] ext_times = [datetime.datetime.time(datetime.datetime.strptime(t, '%h:%m')) t in exts[4]] int_dist = [d d in ints[3]] ext_dist = [d d in exts[3]] fig, ax = plt.subplots() ax.scatter(int_dist, int_times, c='red', s=80) ax.scatter(ext_dist, ext_times, c='blue', s=80) plt.legend(['int', 'ext'], loc=4) plt.xlabel('distance') plt.ylim(0,45000) plt.show()
well possible generate list of time having minute , second. need change format '%m:%s'.
next need change labels using plt.xticks(). changed x axis.
here sample
start = datetime.combine(date.today(), time(0, 0)) axis_times = [] y_values = [] = 0 while i<9: start += timedelta(seconds=7) axis_times.append(start.strftime("%m:%s")) y_values.append(i) i+=1 fig, ax = plt.subplots() ax.scatter(range(len(axis_times)), y_values, c='red', s=80) ax.scatter(range(len(axis_times)), y_values, c='blue', s=20) plt.legend(['int', 'ext'], loc=4) plt.xlabel('distance') plt.xticks(range(len(axis_times)), axis_times, size='small') plt.show()
Comments
Post a Comment