Tuesday, January 11, 2011

Python's Matplotlib and markeredgecolor

When plotting something in matplotlib using the scatter() function, it took me a while to find out that the "markeredgecolor" setting from the plot() function is available, but has a different name: "edgecolor".

In a normal plot(), the main actors are the lines between the data points. In a scatterplot, the main actors are the markers so that does not need be repeated in the name.

An example:
    lines = plt.scatter(x, y, c=colors, marker='o')
    plt.setp(lines, edgecolors='None') #or 'face'. rgba tuples like ((0,0,0,0),) do not seem to work.
    plt.show()

I wanted lines between each of my markers. Instead of trying to coerce scatter() to draw lines or plot() to draw coloured faces (it will not), just call them both.

    plt.plot(x, y, marker='None')
    faces = plt.scatter(x, y, c=color, marker='o')
    plt.setp(faces, edgecolors='face')
    plt.show()

No comments:

Post a Comment