为了账号安全,请及时绑定邮箱和手机立即绑定

Pandas / Pyplot中的散点图:如何按类别绘制

Pandas / Pyplot中的散点图:如何按类别绘制

江户川乱折腾 2019-07-30 11:21:59
Pandas / Pyplot中的散点图:如何按类别绘制我试图使用Pandas DataFrame对象在pyplot中制作一个简单的散点图,但是想要一种有效的方法来绘制两个变量,但是有第三列(键)指示的符号。我尝试过使用df.groupby的各种方法,但没有成功。下面是一个示例df脚本。这会根据'key1'为标记着色,但Id喜欢看到带有'key1'类别的图例。我接近了吗?谢谢。import numpy as npimport pandas as pdimport matplotlib.pyplot as pltdf = pd.DataFrame(np.random.normal(10,1,30).reshape(10,3), index = pd.date_range('2010-01-01', freq = 'M', periods = 10), columns = ('one', 'two', 'three'))df['key1'] = (4,4,4,6,6,6,8,8,8,8)fig1 = plt.figure(1)ax1 = fig1.add_subplot(111)ax1.scatter(df['one'], df['two'], marker = 'o', c = df['key1'], alpha = 0.8)plt.show()
查看完整描述

3 回答

  • 3 回答
  • 0 关注
  • 1979 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信