.. _pylab_examples-eventplot_demo:

pylab_examples example code: eventplot_demo.py
==============================================



.. plot:: /home/tcaswell/source/p/matplotlib/doc/mpl_examples/pylab_examples/eventplot_demo.py

::

    '''
    An eventplot showing sequences of events with various line properties.
    The plot is shown in both horizontal and vertical orientations.
    '''
    
    import matplotlib.pyplot as plt
    import numpy as np
    import matplotlib
    matplotlib.rcParams['font.size'] = 8.0
    
    # set the random seed
    np.random.seed(0)
    
    # create random data
    data1 = np.random.random([6, 50])
    
    # set different colors for each set of positions
    colors1 = np.array([[1, 0, 0],
                        [0, 1, 0],
                        [0, 0, 1],
                        [1, 1, 0],
                        [1, 0, 1],
                        [0, 1, 1]])
    
    # set different line properties for each set of positions
    # note that some overlap
    lineoffsets1 = np.array([-15, -3, 1, 1.5, 6, 10])
    linelengths1 = [5, 2, 1, 1, 3, 1.5]
    
    fig = plt.figure()
    
    # create a horizontal plot
    ax1 = fig.add_subplot(221)
    ax1.eventplot(data1, colors=colors1, lineoffsets=lineoffsets1,
                  linelengths=linelengths1)
    
    
    # create a vertical plot
    ax2 = fig.add_subplot(223)
    ax2.eventplot(data1, colors=colors1, lineoffsets=lineoffsets1,
                  linelengths=linelengths1, orientation='vertical')
    
    # create another set of random data.
    # the gamma distribution is only used fo aesthetic purposes
    data2 = np.random.gamma(4, size=[60, 50])
    
    # use individual values for the parameters this time
    # these values will be used for all data sets (except lineoffsets2, which
    # sets the increment between each data set in this usage)
    colors2 = [[0, 0, 0]]
    lineoffsets2 = 1
    linelengths2 = 1
    
    # create a horizontal plot
    ax1 = fig.add_subplot(222)
    ax1.eventplot(data2, colors=colors2, lineoffsets=lineoffsets2,
                  linelengths=linelengths2)
    
    
    # create a vertical plot
    ax2 = fig.add_subplot(224)
    ax2.eventplot(data2, colors=colors2, lineoffsets=lineoffsets2,
                  linelengths=linelengths2, orientation='vertical')
    
    plt.show()
    

Keywords: python, matplotlib, pylab, example, codex (see :ref:`how-to-search-examples`)