Do not call plt.figuremore than once, as each call creates a new shape (roughly speaking, a window).
import pandas as pd
import numpy as np
import matplotlib.pylab as plt
d = {'City': ['London', 'New York', 'New York', 'London', 'Paris',
'Paris', 'New York', 'New York', 'London', 'Paris'],
'Age': [36., 42., 6., 66., 38., 18., 22., 43., 34., 54],
'Weight': [225, 454, 345, 355, 234, 198, 400, 256, 323, 310]}
df = pd.DataFrame(d)
fig, ax = plt.subplots(figsize=(5, 4))
df.groupby(['City']).plot(kind='scatter', x='Age', y='Weight',
ax=ax,
color=['red', 'blue', 'green'])
plt.show()

plt.subplots fig , ax.ax=ax Panda plot,
.
:
import pandas as pd
import numpy as np
import matplotlib.pylab as plt
d = {'City': ['London', 'New York', 'New York', 'London', 'Paris',
'Paris', 'New York', 'New York', 'London', 'Paris'],
'Age': [36., 42., 6., 66., 38., 18., 22., 43., 34., 54],
'Weight': [225, 454, 345, 355, 234, 198, 400, 256, 323, 310]}
df = pd.DataFrame(d)
groups = df.groupby(['City'])
for city, grp in groups:
fig, ax = plt.subplots(figsize=(5, 4))
grp.plot(kind='scatter', x='Age', y='Weight',
ax=ax)
plt.show()
- , , .
GroupBy 2-: groupby
-DataFrame.
grp, -DataFrame df for.