3

I would like to make a scatter plot with unfilled squares. markerfacecolor is not an option recognized by scatter. I made a MarkerStyle but the fill style seems to be ignored by the scatter plot. Is there a way to make unfilled markers in the scatterplot?

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

def main():
    size = [595, 842] # in pixels
    dpi = 72. # dots per inch
    figsize = [i / dpi for i in size]
    fig = plt.figure(figsize=figsize)
    ax = fig.add_axes([0,0,1,1])

    x_max = 52
    y_max = 90
    ax.set_xlim([0, x_max+1])
    ax.set_ylim([0, y_max + 1]) 

    x = np.arange(1, x_max+1)
    y = [np.arange(1, y_max+1) for i in range(x_max)]

    marker = markers.MarkerStyle(marker='s', fillstyle='none')
    for temp in zip(*y):
        plt.scatter(x, temp, color='green', marker=marker)

    plt.show()

main()
K. Shores
  • 875
  • 1
  • 18
  • 46

2 Answers2

6

It would appear that if you want to use plt.scatter() then you have to use facecolors = 'none' instead of setting fillstyle = 'none' in construction of the MarkerStyle, e.g.

marker = markers.MarkerStyle(marker='s')
for temp in zip(*y):
    plt.scatter(x, temp, color='green', marker=marker, facecolors='none')

plt.show()

or, use plt.plot() with fillstyle = 'none' and linestyle = 'none' but since the marker keyword in plt.plot does not support MarkerStyle objects you have to specify the style inline, i.e.

for temp in zip(*y):
    plt.plot(x, temp, color='green', marker='s', fillstyle='none')

plt.show()

either of which will give you something that looks like this

enter image description here

William Miller
  • 9,839
  • 3
  • 25
  • 46
2

Refer to: How to do a scatter plot with empty circles in Python?

Try adding facecolors='none' to your plt.scatter

plt.scatter(x, temp, color='green', marker=marker, facecolors='none')
Jason
  • 298
  • 2
  • 11
  • Ah, yes. The link off of the scatter documentation. I missed it. Thank you. – K. Shores Dec 25 '19 at 02:46
  • My mistake sorry, I was going off an older version of the page that still listed the facecolors kwarg in the documentation, seems like they some edits. – Jason Dec 25 '19 at 02:52