相关疑难解决方法(0)

使用matplotlib为不同的分类级别绘制不同的颜色

我有此数据帧diamonds,它由被等变量(carat, price, color),我想画的散点图pricecarat为每个color,这意味着不同的color具有在图中不同的颜色.

这很容易在Rggplot:

ggplot(aes(x=carat, y=price, color=color),  #by setting color=color, ggplot automatically draw in different colors
       data=diamonds) + geom_point(stat='summary', fun.y=median)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

我想知道如何在Python中使用matplotlib

PS:

我知道辅助绘图包,比如seabornggplot for python,我不喜欢它们,只是想知道是否有可能matplotlib单独使用,P;

visualization matplotlib pandas

79
推荐指数
6
解决办法
11万
查看次数

matplotlib中图例中的项目是否重复?

我想用这个片段将图例添加到我的情节中:

import matplotlib.pylab as plt

fig = plt.figure()
axes = fig.add_axes([0.1, 0.1, 0.8, 0.8]) # left, bottom, width, height (range 0 to 1)
axes.set_xlabel('x (m)')
axes.set_ylabel('y (m)')
for i, representative in enumerate(representatives):
    axes.plot([e[0] for e in representative], [e[1] for e in representative], color='b', label='Representatives')
axes.scatter([e[0] for e in intersections], [e[1] for e in intersections], color='r', label='Intersections')
axes.legend()   
Run Code Online (Sandbox Code Playgroud)

我最终得到了这个情节

在此输入图像描述

显然,这些项目在图中是重复的.我该如何更正此错误?

python matplotlib

23
推荐指数
4
解决办法
2万
查看次数

标签 统计

matplotlib ×2

pandas ×1

python ×1

visualization ×1