In matplot, how to set the color in this case?

Hello!
I would like to make animation usinig this class.
The label list is [‘A’, ‘B’, ‘C’, ‘D’].
For now, the line colors are applied by default.
However the default value has poor visibility, so I want to change each color. (‘grey’, ‘black’, ‘blue’, ‘limegreen’)

How to adjust the code below?


class TrajectoryAnimation3D(animation.FuncAnimation):

def __init__(self, *paths, zpaths, labels=[], fig=None, ax=None, frames=None,
             interval=60, repeat_delay=5, blit=True, **kwargs):
    if fig is None:
        if ax is None:
            fig, ax = plt.subplots()
        else:
            fig = ax.get_figure()
    else:
        if ax is None:
            ax = fig.gca()
    self.fig = fig
    self.ax = ax
    self.paths = paths
    self.zpaths = zpaths
    if frames is None:
        frames = max(path.shape[1] for path in paths)
    self.lines = [ax.plot([], [], [], '-',label=labels, alpha=1.0, lw=2.0)[0]
                  for _, label in zip_longest(paths, labels)]

Hi @BobKim,

Could you not edit this line to zip over your list of [‘grey’, ‘black’, ‘blue’, ‘limegreen’] as well?

So, something like,

colors = [‘grey’, ‘black’, ‘blue’, ‘limegreen’]
self.lines = [ax.plot([], [], [], '-', color=color, label=labels, alpha=1.0, lw=2.0)[0]
                  for _, label, color in zip_longest(paths, labels, colors)]
1 Like