Skip to main content

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:

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')
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 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()
so far good.

however, want plot 2 lines using plot_date, , don't seem able working. tried following:
code:
list2 = [1,2,4,8,16]  plt.plot_date(dates_float, list1, linestyle='-', dates_float, list2, linestyle='--', xdate=true, ydate=false)
and
code:
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)
both of these however, result in: syntaxerror: non-keyword arg after keyword arg

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:
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()
cheers!


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

Popular posts from this blog

How to set the order of FAQs instead of alphabetical

Thread: Get UK Keyboard working

how do I change the e-mail address for my merchant account