python-2.7 - Pandas 使用字符绘制两个变量

标签 python-2.7 pandas plot

我正在尝试绘制两个具有不同字符和颜色的变量 fdr_new 和 fdr_old做错了(只粘贴 df.head())

df:

df = pd.read_csv('~/plot.txt', sep='\t')
df.head()
id1 fdr_new fdr_old
a   0.025673    0.004912
b   0.098444    0.002133
c   0.00003 0.000004
d   0.330957    0.302002
e   0.939168    0.932705

代码:

coff.plot(x='fdr_new', y='fdr_old', style=['bo','rx'])

绘图使用代码:

import pandas as pd 
import seaborn as sns
%matplotlib inline
import matplotlib.pyplot as plt
%config InlineBackend.figure_format = 'retina'
rd = pd.read_clipboard()
rd.head()
        id1 fdr_new fdr_old
0   a   0.025673    0.004912
1   b   0.098444    0.002133
2   c   0.000030    0.000004
3   d   0.330957    0.302002
4   e   0.939168    0.932705
rd.plot(x = 'id1', y = ['fdr_new','fdr_old'], style=['bo','rx'])

enter image description here

改变颜色: enter image description here

关闭并停止后: enter image description here

更改样式与删除 import 'retina' 命令一起完成了这项工作。 enter image description here

最佳答案

这是一个散点图,其中每个点都是坐标对,一部分来自 fdf_new,另一部分来自 fdr_old。此图上没有任何意义仅来自 fdr_newfdr_old。因为您的 fdr_old 被指定为您的 y 轴,所以它被假定为系列名称,这就是您在图例中看到它的原因。但是只使用了第一种样式......因为你只有一个系列的点。

我认为要协调您正在尝试做的事情的唯一方法是将 fdr_oldfdr_new 视为单独的时间序列。

df[['fdr_old', 'fdr_new']].plot(style=['bo', 'rx'])

enter image description here

您甚至可以将 id1 放在 x 轴上

df.set_index('id1').plot(style=['bo', 'rx'])

enter image description here

关于python-2.7 - Pandas 使用字符绘制两个变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44572184/

相关文章:

python - 有谁知道将现有 csv 文件转换为 UTF-8 编码的简单函数?

python - 将列列表更改为不同数据类型的更Pythonic(或pandorable)的方法

r - 在ggplot2中通过labeller=label_wrap包裹长轴标签

matlab - 如何在matlab中绘制3d有向图

python - 如何打开与 Python 2 和 Python 3 兼容的 Tkinter AskOpenFileName 对话框

Python:如何将 '-help' 添加到 argparse 帮助命令列表?

python - django.db.utils.OperationalError : near "񐁂򐁇N": syntax error

python - DataFrame 索引与日期系列

python - 如何显示我的 PCA 绘图?

R ggplot2错误: stacking not well defined when ymin! =0