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

时间:2020-09-15 02:43:06

标签: python pandas matplotlib data-visualization scatter-plot

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

2 个答案:

答案 0 :(得分:1)

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

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

输出:

enter image description here

答案 1 :(得分:1)

  • 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