【发布时间】:2015-03-27 08:01:11
【问题描述】:
我的问题如下。
我有一个 pandas DataFrame,其中包含第一行中的“样本”数据和所有其他行中的“控件”数据。 我想要一个散点图(或任何其他类型的图来概括问题),其中所有“控件”都是一种颜色,而“样本”是另一种颜色。怎么做?我查看了 pandas 文档,但找不到任何东西。
这是我目前所拥有的
from pandas import *
from collections import OrderedDict
mydict = OrderedDict([
('sample', [454, 481, 160, 26, 17]),
('ctrl_1', [454, 470, 101, 10, 8]),
('ctrl_2', [454, 473, 110, 15, 9]),
('ctrl_3', [454, 472, 104, 19, 13]),
('ctrl_4', [454, 472, 105, 16, 13]),
('ctrl_5', [454, 466, 97, 15, 10]),
('ctrl_6', [454, 473, 110, 17, 10]),
('ctrl_7', [454, 465, 99, 15, 11]),
('ctrl_8', [454, 471, 107, 18, 12]),
('ctrl_9', [454, 471, 102, 15, 11]),
('ctrl_10', [454, 472, 116, 14, 9])
])
df = DataFrame.from_dict(mydict,orient='index')
df.columns=['A','B','C','D','E']
df.plot(kind='scatter',x='C',y='E',figsize=(10,10), color='blue')
我尝试将 DataFrame 拆分为两部分(控件和示例)并将一个绘制在另一个之上,但是当您尝试对单个点进行散点图(这是一个错误吗?)。
sample = df.ix[0]
controls = df.ix[1:]
controls.plot(kind='scatter',x='C',y='E',figsize=(10,10), color='blue')
sample.plot(kind='scatter',x='C',y='E',figsize=(10,10), color='red')
有什么建议吗?
【问题讨论】:
标签: python pandas colors scatter-plot