pandas 散点图和 groupby 不起作用

pandas scatter plot and groupby does not work

我正在尝试用 pandas 绘制散点图。不幸的是 kind='scatter' 不起作用。如果我将其更改为 kind='line' 它会按预期工作。我该怎么做才能解决这个问题?

for label, d in df.groupby('m'):
    d[['te','n']].sort_values(by='n', ascending=False).plot(kind="scatter", x='n', y='te', ax=ax, label='m = '+str(label))```

改用plot.scatter

df = pd.DataFrame({'x': [0, 5, 7,3, 2, 4, 6], 'y': [0, 5, 7,3, 2, 4, 6]})
df.plot.scatter('x', 'y')

如果您需要单独的标签和颜色,请使用此代码段:

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

df = pd.DataFrame({
    'm': np.random.randint(0, 5, size=100),
    'x': np.random.uniform(size=100),
    'y': np.random.uniform(size=100),
})

fig, ax = plt.subplots()
for label, d in df.groupby('m'):
    # generate a random color:
    color = list(np.random.uniform(size=3))
    d.plot.scatter('x', 'y', label=f'group {label}', ax=ax, c=[color])