X Tutup
Skip to content

can't create single legend line with different point types #2018

@jslavin

Description

@jslavin

Hi,

I'd like to create a legend for a plot with a single label applying to two different types of points -- i.e. having different colors and marker types. There doesn't seem to be any way of doing this. Here's some simple demonstration code:

fig, ax = plt.subplots()
p1 = ax.scatter([0.1],[0.5],c='r',marker='s')
p2 = ax.scatter([0.3],[0.2],c='b',marker='o')
l = ax.legend((p1,p2),['points'],scatterpoints=2)
plt.show()

This yields a legend with two red squares. What I want is a red square and a blue circle. I've tried variations on the legend call and have not been able to find a way to get this to work (though it is possible to use ncol=2 and an empty string for one of the labels, this leaves a wide gap between the points). I think there should be a way to do this. This is somewhat related to the issue that, though one can give a sequence of colors for points in a call to scatter, there is no way to give a sequence of marker types.

Jon

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      X Tutup