Sunday 15 March 2015

python - Setting colors using color cycle on date plots using `plot_date()` -


I am currently trying to plot several date graphs using the matplotlibs plot_date function I am One thing I did not understand is how to assign a different color to each article automatically (as with plot axes.color_cycle setting matplotlib .rcParams ). Example Code: import import matplotlib.pyplot as mpt import matplotlib.dates mdates value = xrange (1, 13) dates = [Dt import matlotlib as dt import time as datetime Import] i [i, 1, i, 0, 0, 0] for i in ['axes.color_cycle'] = ['r', 'g']: i for i (0, 1, 2) Mpl.rcParams: nv = map (lambda k: k + i, value) d = mdates.date2num (dates) plt.plot_date (d, nv, ls = "solid") plt.show ()

This gives me a nice shape with 3 lines in them but they all have the same color May include. Changing the call to plot_date in just three lines in red and green on plot , but unfortunately the X axis labels are no longer useful.

So my question is whether there is no way to color to work with plot_date , just as it is just plot Does it for

A good way to solve this problem came up:

  TCSWell explained that this function is set to  fmt = 'bo'; ax.plot_date (d, nv, ls = 'solid', fmt = '')   

By default, and the user can overwrite this by passing the argument fmt while calling plot_date () .

By doing so, the result will be:

Enter image details here

No comments:

Post a Comment