我想用未填充的正方形绘制散点图。 scatter无法识别markerfacecolor
。我做了一个MarkerStyle
,但散点图似乎忽略了填充样式。有没有办法在散点图中制作未填充的标记?
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()
答案 0 :(得分:2)
看来,如果要使用plt.scatter()
,则必须使用facecolors = 'none'
而不是在fillstyle = 'none'
的构造中设置MarkerStyle
,例如
marker = markers.MarkerStyle(marker='s')
for temp in zip(*y):
plt.scatter(x, temp, color='green', marker=marker, facecolors='none')
plt.show()
或将plt.plot()
与fillstyle = 'none'
和linestyle = 'none'
一起使用,但是由于marker
中的plt.plot
关键字不支持MarkerStyle
对象,指定内联样式,即
for temp in zip(*y):
plt.plot(x, temp, color='green', marker='s', fillstyle='none')
plt.show()
这两种方法都会给您带来如下效果
答案 1 :(得分:1)
引用:How to do a scatter plot with empty circles in Python?
尝试将facecolors='none'
添加到您的plt.scatter
plt.scatter(x, temp, color='green', marker=marker, facecolors='none')