Changing symbols instead of colors for lines ...

Hello all,

Usually when I plot two or more lines, the color of the lines change.
Is it possible to change this default behavior so that when I plot two
or more lines, the symbols change and not the color.

This would be useful if someone is trying to make plots in black and
white so that the symbols change instead of line colors.

Regards,
Chaitanya

Hello all,

Usually when I plot two or more lines, the color of the lines change.
Is it possible to change this default behavior so that when I plot two
or more lines, the symbols change and not the color.

This would be useful if someone is trying to make plots in black and
white so that the symbols change instead of line colors.

You can do this with a little manual intervention -- below is a script
which cycles through all of mpl's line markers.

    import numpy as np
    import matplotlib.lines as lines
    import matplotlib.pyplot as plt

    markers = list(lines.Line2D.markers.keys())
    markers.sort()
    N = len(markers)

    fig = plt.figure()
    ax = fig.add_subplot(111)
    x = np.arange(20)
    for i in range(50):
        marker = markers[i%N]
        print marker
        y = i*x
        ax.plot(x, y, marker=marker, linestyle='', mfc='blue')

    plt.show()

You could do a similar trick with linestyles using the
lines.Line2D.lineStyles and lines.Line2D.drawStyles dictionaries
(these map the symbols to the internal Line2D function we use to draw
the symbols). See also

  http://matplotlib.sourceforge.net/examples/pylab_examples/line_styles.html

JDH

···

On Tue, Apr 14, 2009 at 8:09 AM, Chaitanya Krishna <icymist@...287...> wrote:

Regards,
Chaitanya

------------------------------------------------------------------------------
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Also, you can use itertools.cycle to loop over a set of markers probably a bit more cleanly than the example:

markers = itertools.cycle(lines.Line2D.markers.keys())
marker = markers.next()

Ryan

···

On Tue, Apr 14, 2009 at 8:50 AM, John Hunter <jdh2358@…83…287…> wrote:

On Tue, Apr 14, 2009 at 8:09 AM, Chaitanya Krishna <icymist@…287…> wrote:

Hello all,

Usually when I plot two or more lines, the color of the lines change.

Is it possible to change this default behavior so that when I plot two

or more lines, the symbols change and not the color.

This would be useful if someone is trying to make plots in black and

white so that the symbols change instead of line colors.

You can do this with a little manual intervention – below is a script

which cycles through all of mpl’s line markers.

import numpy as np

import matplotlib.lines as lines

import matplotlib.pyplot as plt



markers = list(lines.Line2D.markers.keys())

markers.sort()

N = len(markers)



fig = plt.figure()

ax = fig.add_subplot(111)

x = np.arange(20)

for i in range(50):

    marker = markers[i%N]

    print marker

    y = i*x

    ax.plot(x, y, marker=marker, linestyle='', mfc='blue')



plt.show()

You could do a similar trick with linestyles using the

lines.Line2D.lineStyles and lines.Line2D.drawStyles dictionaries

(these map the symbols to the internal Line2D function we use to draw

the symbols). See also

http://matplotlib.sourceforge.net/examples/pylab_examples/line_styles.html


Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma

Sent from Norman, Oklahoma, United States

Yes, that is better that the somewhat opaque i%N trick. And the call
to "keys()" is unnecessary because the iterator will cycle over the
keys of the dict anyhow, but I think it makes it a little clearer what
kind of data structure you are working with.

JDH

···

On Tue, Apr 14, 2009 at 8:56 AM, Ryan May <rmay31@...287...> wrote:

Also, you can use itertools.cycle to loop over a set of markers probably a
bit more cleanly than the example:

markers = itertools.cycle(lines.Line2D.markers.keys())
marker = markers.next()