本文是接着这篇内容的:https://blog.csdn.net/Cassiel60/article/details/88350442
散点图是用于研究两个变量之间关系的经典的和基本的图表。 如果数据中有多个组,则可能需要以不同颜色可视化每个组。 在 matplotlib 中,您可以使用 plt.scatterplot()
方便地执行此操作
#Import dataset
midwest = pd.read_csv("https://raw.githubusercontent.com/selva86/datasets/master/midwest_filter.csv")
# prepare data
#create as many colors as there are unique midwest['category']
categories = np.unique(midwest['category'])
colors = [plt.cm.tab10(i/float(len(categories)-1)) for i in range(len(categories))]
# draw plot for each category
plt.figure(figsize=(16,10),dpi=80,facecolor='w',edgecolor='k')
for i ,category in enumerate(categories):
plt.scatter('area','poptotal',
data = midwest.loc[midwest.category==c