问题描述
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')
输出:
,- 在
matplotlib
文档中很难找到,但是似乎fc
和ec
分别是facecolor
和edgecolor
的别名。 -
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')
# penguins is a pandas dataframe
penguins[['bill_length_mm','bill_depth_mm']].plot.scatter('bill_depth_mm','bill_length_mm',ec='g',fc='none')