出于舒适的原因,我将使用^{}语法,但应该(几乎)与轴向散射. 在import pandas as pd
import matplotlib.pyplot as plt
df = pd.DataFrame({'c': ['News', 'Hobbies & Interests', 'Arts & Entertainment', 'Internal Use', 'Business', 'Internal Use', 'Internal Use', 'Ad Impression Fraud', 'Arts & Entertainment', 'Adult Content', 'Arts & Entertainment', 'Internal Use', 'Internal Use', 'Reference', 'News', 'Shopping', 'Food & Drink', 'Internal Use', 'Internal Use', 'Reference'],
'x': [-95.44078826904297, 127.71454620361328, -491.93121337890625, 184.5579071044922, -191.46273803710938, 95.22545623779297, 272.2229919433594, -67.099365234375, -317.60797119140625, -175.90196228027344, -491.93121337890625, 214.3858642578125, 184.5579071044922, 346.4012756347656, -151.8809051513672, 431.6130676269531, -299.4017028808594, 184.5579071044922, 184.5579071044922, 241.29026794433594],
'y': [-40.87070846557617, 245.00514221191406, 43.07831954956055, -458.2991638183594, 270.4497985839844, -453.2981262207031, -439.6551513671875, -206.3104248046875, 205.25787353515625, -58.520164489746094, 43.07831954956055, -182.91664123535156, -458.2991638183594, 19.559282302856445, -281.3316650390625, 103.6922378540039, 280.2445373535156, -458.2991638183594, -458.2991638183594, -113.96920776367188]})
df['col'] = df.c.astype('category').cat.codes
cmap = plt.cm.get_cmap('jet', df.c.nunique())
ax = df.plot.scatter(
x='x',y='y', c='col',
cmap=cmap
)
plt.show()
这里get_cmap接受一个cmap名称(您可以在this example page上找到各种映射的名称)和
^{bq}$
上述代码产生以下结果:
如果要添加批注并取消颜色栏,请使用:
^{pr2}$
得到以下结果:
提示:如果太小,请使用plt.scatter(x,y,s=None, c=None, **kwds)中的“s”参数更改大小。在