Thread: [Python] How to plot multiple lines with plot_date() in matplotlib
hello,
need plot image 2 independent lines trying matplotlib. have no trouble creating image using 2 lines:
i want x-axis line of dates, need use plot_date that. first created image using 1 line (using date2num create desired floats):code:import matplotlib.pyplot plt import numpy np t = np.arange(0., 5., 0.2) g = np.arange(0., 10., 0.4) plt.plot(t, t, 'r--', t, g, 'bs')
so far good.code:import matplotlib.pyplot plt import datetime import matplotlib dates_in_string = ['2010-01-01', '2010-01-02', '2010-02-03', '2010-04-05', '2010-07-19'] dates_datetime = [] d in dates_in_string: dates_datetime.append(datetime.datetime.strptime(d, '%y-%m-%d')) dates_float = matplotlib.dates.date2num(dates_datetime) list1 = [1,2,3,4,5] plt.plot_date(dates_float, list1, linestyle='-', tz=none, xdate=true, ydate=false) plt.show()
however, want plot 2 lines using plot_date, , don't seem able working. tried following:
andcode:list2 = [1,2,4,8,16] plt.plot_date(dates_float, list1, linestyle='-', dates_float, list2, linestyle='--', xdate=true, ydate=false)
both of these however, result in: syntaxerror: non-keyword arg after keyword argcode:list2 = [1,2,4,8,16] plt.plot_date(dates_float, list1, linestyle='-', tz=none, xdate=true, ydate=false, dates_float, list2, linestyle='--', tz=none, xdate=true, ydate=false)
wouldn' t know doing wrong here though. far know give arguments correctly.
have idea how create 2 lines in 1 plot_date image?
alright! got working!
after while found out shouldn't in 1 plot_date(), can/need 2 plot_date()'s.
future reference; solved this:
cheers!code:import matplotlib.pyplot plt import datetime import matplotlib dates_in_string = ['2010-01-01', '2010-01-02', '2010-02-03', '2010-04-05', '2010-07-19'] dates_datetime = [] d in dates_in_string: dates_datetime.append(datetime.datetime.strptime(d, '%y-%m-%d')) dates_float = matplotlib.dates.date2num(dates_datetime) list1 = [1,2,3,4,5] list2 = [1,2,4,8,16] plt.plot_date(dates_float, list1, linestyle='-', xdate=true, ydate=false) plt.plot_date(dates_float, list2, linestyle='-', xdate=true, ydate=false) plt.show()
Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk [SOLVED] [Python] How to plot multiple lines with plot_date() in matplotlib
Ubuntu
Comments
Post a Comment