熊猫在线变换hbar

时间:2016-08-04 11:39:46

标签: python pandas matplotlib plot

我有一个pandas hbar情节,但我希望有一条线而不是条纹(只是一条线到了条形顶部)。

这可能吗?

我有

b3["R2_foret"].plot(legend=False, kind='barh')    

给了我

enter image description here

我不希望看到所有这些蓝色,只是从一个值到下一个值的一条线。 问题是要制作一条垂直线。

修改

通过unutbu遵循以下解决方案,alpha = 0

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

b3 = pd.DataFrame({'R2_foret': [0.79381443298969068, 0.7766323024054983, 0.7903780068728522, 0.78006872852233677, 0.79725085910652915, 0.79725085910652915, 0.8041237113402061, 0.7903780068728522, 0.7903780068728522, 0.81443298969072153, 0.80068728522336763, 0.80756013745704458, 0.85567010309278368, 0.8556701030927838, 0.87628865979381465, 0.84536082474226804, 0.86597938144329922, 0.87628865979381454, 0.85910652920962216, 0.85910652920962227, 0.87579774177712344, 0.87628865979381465, 0.84536082474226792, 0.86597938144329922, 0.87628865979381454, 0.88316151202749149, 0.89347079037800703, 0.90378006872852246, 0.90378006872852246, 0.90034364261168398, 0.9106529209621993, 0.90378006872852246, 0.90721649484536093, 0.9101620029455082, 0.9106529209621993, 0.92096219931271495, 0.90721649484536093, 0.92096219931271495, 0.92096219931271495, 0.91408934707903777]}) 

b3['y'] = np.arange(len(b3))
ax = b3.plot(x='R2_foret', y='y', style=['-'])
b3['R2_foret'].plot(kind='barh', ax=ax, alpha=0)
plt.xlim(0,1)
plt.tick_params(left='off', labelleft='off')
plt.show()

enter image description here

3 个答案:

答案 0 :(得分:0)

你的意思是

b3["R2_foret"].plot()

答案 1 :(得分:0)

关闭的事情:

b3["R2_foret"].plot(legend=False, drawstyle="steps") 

答案 2 :(得分:0)

指定y值的新列:

b3['x'] = np.arange(len(b3))

然后绘制yR2_foret的对比:

 b3.plot(x='R2_foret', y='y', style=['o-'])

例如,

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

b3 = pd.DataFrame({'R2_foret': [0.79381443298969068, 0.7766323024054983, 0.7903780068728522, 0.78006872852233677, 0.79725085910652915, 0.79725085910652915, 0.8041237113402061, 0.7903780068728522, 0.7903780068728522, 0.81443298969072153, 0.80068728522336763, 0.80756013745704458, 0.85567010309278368, 0.8556701030927838, 0.87628865979381465, 0.84536082474226804, 0.86597938144329922, 0.87628865979381454, 0.85910652920962216, 0.85910652920962227, 0.87579774177712344, 0.87628865979381465, 0.84536082474226792, 0.86597938144329922, 0.87628865979381454, 0.88316151202749149, 0.89347079037800703, 0.90378006872852246, 0.90378006872852246, 0.90034364261168398, 0.9106529209621993, 0.90378006872852246, 0.90721649484536093, 0.9101620029455082, 0.9106529209621993, 0.92096219931271495, 0.90721649484536093, 0.92096219931271495, 0.92096219931271495, 0.91408934707903777]}) 

b3['y'] = np.arange(len(b3))
ax = b3.plot(x='R2_foret', y='y', style=['o-'])
b3['R2_foret'].plot(kind='barh', ax=ax, alpha=0.3)
plt.xlim(0,1)
plt.tick_params(left='off', labelleft='off')
plt.show()

enter image description here