如何从matplotlib 3.3.1获取没有填充的标记?

问题描述

matplotlib.pyplot.scatter一个facecolors=None参数,该参数将使数据点标记的内部呈空心。如何为pandas.DataFrame.plot.scatter()获得相同的外观?

解决方法

这是选项c(请注意,即使'None'中的None也是facecolors而不是plt):

df.plot.scatter(x='x',y='y',c='None',edgecolors='C1')

输出:

enter image description here

,
  • matplotlib文档中很难找到,但是似乎fcec分别是facecoloredgecolor的别名。
  • pandas绘图引擎为matplotlib
  • 参数为fc。要使用fc,您还应该使用ec
    • 指定fc='none'而不指定ec将导致空白标记。
  • 'None''none'均有效,但None无效。
import seaborn as sns  # for data
import matplotlib.pyplot as plt

# load data
penguins = sns.load_dataset("penguins",cache=False)

# set x and y
x,y = penguins["bill_length_mm"],penguins["bill_depth_mm"]

# plot
plt.scatter(x,y,fc='none',ec='g')

enter image description here

# penguins is a pandas dataframe
penguins[['bill_length_mm','bill_depth_mm']].plot.scatter('bill_depth_mm','bill_length_mm',ec='g',fc='none')

enter image description here