symbol skip in plot command

Hi all,

I am trying to find a solution to the following problem (without
success so far):
I have some high frequency data which I want to plot with a simple
plot command using a solid line and a symbol. However, since I have many
many
data points I want to plot the symbol only every N'th data point. Is
there a skip parameter
or any other way to tell matplotlib to actually plot the symbol only
at every N'th data point (I know it is possible in grace which I have
stopped
using in favour of matplotlib). Plotting the data twice- the first time
without
symbol showing every data point and the second time onlywith the symbol
and some skip in the data - doesn't help as I now get two entities in
the legend.

Thanks for any help

Michael

There is a way to do this, but it is not terribly elegant. The tricky
part is to get the legend right::

    import numpy as np
    import matplotlib.pyplot as plt
    fig = plt.figure()
    ax = fig.add_subplot(111)

    N = 10
    x = np.arange(100.)
    y = x**2

    # the solid line, suppress auto legend
    line1, = ax.plot(x, y, linestyle='-', color='black', label='_nolegend_')
    # every N-th marker, suppress auto legend
    line2, = ax.plot(x[::N], y[::N], linestyle='', marker='o',
markerfacecolor='blue', label='_nolegend_')

    # the proxy line, both solid and markers. Don't add it to plot, just
    # use it in legend
    import matplotlib.lines as lines
    proxyline = lines.Line2D([0,1], [0,1], linestyle='-',
color='black', marker='o', markerfacecolor='blue')

    leg = ax.legend([proxyline], ['my label'])

    plt.show()

JDH

···

On Tue, Dec 16, 2008 at 10:09 AM, Michael Oevermann <michael.oevermann@...281...> wrote:

Hi all,

I am trying to find a solution to the following problem (without
success so far):
I have some high frequency data which I want to plot with a simple
plot command using a solid line and a symbol. However, since I have many
many
data points I want to plot the symbol only every N'th data point. Is
there a skip parameter
or any other way to tell matplotlib to actually plot the symbol only
at every N'th data point (I know it is possible in grace which I have
stopped
using in favour of matplotlib). Plotting the data twice- the first time
without
symbol showing every data point and the second time onlywith the symbol
and some skip in the data - doesn't help as I now get two entities in
the legend.

I just added a new line property called "markevery" to support
subsampling markers. Included below is the docstring and nosetest
which should clearly indicate usage:

    def set_markevery(self, every):
        """
        Set the markevery property to subsample the plot when using
        markers. Eg if ``markevery=5``, every 5-th marker will be
        plotted. *every* can be

        None
            Every point will be plotted

        an integer N
            Every N-th marker will be plotted starting with marker 0

        A length-2 tuple of integers
            every=(start, N) will start at point start and plot every
N-th marker

        ACCEPTS: None | integer | (startind, stride)

        """

def test_markevery():
    x, y = np.random.rand(2, 100)

    # check marker only plot
    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.plot(x, y, 'o')
    ax.plot(x, y, 'd', markevery=None)
    ax.plot(x, y, 's', markevery=10)
    ax.plot(x, y, '+', markevery=(5, 20))
    fig.canvas.draw()
    plt.close(fig)

    # check line/marker combos
    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.plot(x, y, '-o')
    ax.plot(x, y, '-d', markevery=None)
    ax.plot(x, y, '-s', markevery=10)
    ax.plot(x, y, '-+', markevery=(5, 20))
    fig.canvas.draw()
    plt.close(fig)

···

On Tue, Dec 16, 2008 at 10:30 AM, John Hunter <jdh2358@...287...> wrote:

using in favour of matplotlib). Plotting the data twice- the first time
without
symbol showing every data point and the second time onlywith the symbol
and some skip in the data - doesn't help as I now get two entities in
the legend.

There is a way to do this, but it is not terribly elegant. The tricky
part is to get the legend right::

That's exactly what I was looking for! But how do I get the new feature into my
matplotlib version?

Michael

John Hunter schrieb:

···

On Tue, Dec 16, 2008 at 10:30 AM, John Hunter <jdh2358@...287...> wrote:

using in favour of matplotlib). Plotting the data twice- the first time
without
symbol showing every data point and the second time onlywith the symbol
and some skip in the data - doesn't help as I now get two entities in
the legend.
      

There is a way to do this, but it is not terribly elegant. The tricky
part is to get the legend right::
    
I just added a new line property called "markevery" to support
subsampling markers. Included below is the docstring and nosetest
which should clearly indicate usage:

    def set_markevery(self, every):
        """
        Set the markevery property to subsample the plot when using
        markers. Eg if ``markevery=5``, every 5-th marker will be
        plotted. *every* can be

        None
            Every point will be plotted

        an integer N
            Every N-th marker will be plotted starting with marker 0

        A length-2 tuple of integers
            every=(start, N) will start at point start and plot every
N-th marker

        ACCEPTS: None | integer | (startind, stride)

        """

def test_markevery():
    x, y = np.random.rand(2, 100)

    # check marker only plot
    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.plot(x, y, 'o')
    ax.plot(x, y, 'd', markevery=None)
    ax.plot(x, y, 's', markevery=10)
    ax.plot(x, y, '+', markevery=(5, 20))
    fig.canvas.draw()
    plt.close(fig)

    # check line/marker combos
    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.plot(x, y, '-o')
    ax.plot(x, y, '-d', markevery=None)
    ax.plot(x, y, '-s', markevery=10)
    ax.plot(x, y, '-+', markevery=(5, 20))
    fig.canvas.draw()
    plt.close(fig)

Either wait for the next release and use the workaround for now, or
install from svn. See

  http://matplotlib.sourceforge.net/faq/installing_faq.html#install-from-svn

Nightly builds are on the list of things to do, but we have bigger
fish to fry at the moment. What platform are you on?

···

On Tue, Dec 16, 2008 at 2:20 PM, Michael Oevermann <michael.oevermann@...281...> wrote:

That's exactly what I was looking for! But how do I get the new feature
into my
matplotlib version?