pandas plot two variables using character

2020-03-26 08:37发布

I am trying to plot two variables fdr_new and fdr_old with different characters and color blue and o for fdr_old red and x for fdr_new below is what I have tried I do not see any red and x on my plot not sure what I am doing wrong (pasting only 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

code:

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

plot using code:

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

changing color: enter image description here

after close and halt: enter image description here

changing style did the job along with removing the import 'retina' command. enter image description here

2条回答
等我变得足够好
2楼-- · 2020-03-26 09:31

You can use multiple Y-axis parameters

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

enter image description here

查看更多
家丑人穷心不美
3楼-- · 2020-03-26 09:35

This is a scatter plot where each point is coordinate pair consisting of one part from fdf_new and the other part from fdr_old. No point on this plot is from only fdr_new or fdr_old. Because your fdr_old is specified as your y-axis it is assumed as the series name and thats why you see it in the legend. But only the first style is used... because you only have one series of points.

The only way I can see to reconcile what I think you are trying to do is to treat fdr_old and fdr_new as separate timeseries.

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

enter image description here

You can even put id1 in the x-axis

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

enter image description here

查看更多
登录 后发表回答