如何将“markersize”参数添加到 DataFrame 图中?

pas*_*sei 4 python plot matplotlib

我正在尝试绘制 DataFrame 并且我想修改标记大小,但似乎我无法在同一个 plot() 调用中执行此操作。

ax0 = df_can_t.plot(kind='scatter', x='Year', y='China', \
figsize=(30,10), color = 'red', marker= '+', markersize = 14.0)
Run Code Online (Sandbox Code Playgroud)

我收到错误:AttributeError:未知属性标记大小。

但是,似乎允许使用“标记大小”(https://matplotlib.org/api/_as_gen/matplotlib.pyplot.plot.html),所以我不确定问题是什么。

Sco*_*ton 6

使用scatter plot,您的大小参数只是s,请尝试:

ax0 = df_can_t.plot(kind='scatter', x='Year', y='China', \
figsize=(30,10), color = 'red', marker= '+', s = 14.0)
Run Code Online (Sandbox Code Playgroud)

这是一个MVCE:

import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

df = sns.load_dataset('iris')

ax = df.plot(kind='scatter', x='petal_width', y='sepal_width', s=10.0)
Run Code Online (Sandbox Code Playgroud)

输出:

在此处输入图片说明