Search code examples
pythonmatplotlibscatter-plot

Marker filling options Matplotlib


I need more marker-filling options. I came up with this trick to make a more interesting marker without using colours.

fig, ax = plt.subplots()
a = np.random.random(5)
b = np.random.random(5)
[ax.scatter(a, b, s=eses, edgecolor='k', lw=.5, color='None', label = 'This is not what I want') for eses in [200, 100, 30, 1]]
ax.set_title('Marker options')
ax.legend()
plt.show()

Example

I have two questions:

  1. how to fix the legend so that the same concentric rings show up as one symbol in the legend instead of four symbols of different sizes.

  2. how to get a dashed circle for a marker (circle with parallel - diagonal lines inside of it), or a circle filled with dots.


EDIT: Thanks to the users who commented. I've seen both websites suggested before posting my question; however, I am not looking for custom marker shapes. I am looking for custom fillings for a simple circle marker.


Solution

  • I found what I was looking for, it was the hatch option:

    plt.title('Marker options')
    plt.scatter(range(3), range(3), s=150, edgecolor='k', c='w', hatch='ooo', label='option 1')
    plt.scatter(np.linspace(.2,4,3), np.linspace(0,3,3), s=200, edgecolor='k', c='w', hatch='+++', label='option 2')
    plt.scatter(np.linspace(0,5,3), np.linspace(4,0,3), s=200, edgecolor='k', c='w', hatch='***', label='option 3')
    plt.scatter(np.linspace(0,3,3), np.linspace(4,1,3), s=200, edgecolor='k', c='w', hatch='/////', label='option 4')
    plt.legend()
    plt.show()
    

    enter image description here