Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matplotlib scatter plot of unfilled squares

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()
like image 873
K. Shores Avatar asked Oct 27 '25 05:10

K. Shores


1 Answers

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

like image 127
William Miller Avatar answered Oct 29 '25 18:10

William Miller



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!