我想制作一个带有未填充方块的散点图。不是scattermarkerfacecolor
识别的选项。我做了一个,但填充样式似乎被散点图忽略了。有没有办法在散点图中制作未填充的标记?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()
Run Code Online (Sandbox Code Playgroud)
看来,如果你想使用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()
Run Code Online (Sandbox Code Playgroud)
或者,plt.plot()
与fillstyle = 'none'
and 一起使用linestyle = 'none'
,但由于marker
关键字 inplt.plot
不支持MarkerStyle
对象,因此您必须指定内联样式,即
for temp in zip(*y):
plt.plot(x, temp, color='green', marker='s', fillstyle='none')
plt.show()
Run Code Online (Sandbox Code Playgroud)
其中任何一个都会给你看起来像这样的东西
归档时间: |
|
查看次数: |
6013 次 |
最近记录: |