<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def plot_color_legend(legend, horizontal=False, ax=None):
 """ Plot a pandas Series with labels and colors. Parameters legend : pandas.Series Pandas Series whose values are RGB triples and whose index contains categorical labels. horizontal : bool If True, plot horizontally. ax : matplotlib.axis Axis to plot on. Returns ------- ax : matplotlib.axis Plot axis. """

    import matplotlib.pyplot as plt
    import numpy as np
    t = np.array([np.array([x for x in legend])])
    if ax is None:
        fig, ax = plt.subplots(1, 1)
    if horizontal:
        ax.imshow(t, interpolation='none')
        ax.set_yticks([])
        ax.set_xticks(np.arange(0, legend.shape[0]))
        t = ax.set_xticklabels(legend.index)
    else:
        t = t.reshape([legend.shape[0], 1, 3])
        ax.imshow(t, interpolation='none')
        ax.set_xticks([])
        ax.set_yticks(np.arange(0, legend.shape[0]))
        t = ax.set_yticklabels(legend.index)
    return ax