我有一个pandas DataFrame ten_day
,如下所示:
XLF US Equity NaN
PEO PW Equity -2.797857
GLE FP Equity 4.497489
CBK GY Equity 6.162684
BAC US Equity NaN
UCG IM Equity 4.250801
ITRXESE Index -0.996103
HSBC US Equity NaN
RBS LN Equity -1.347926
CABK SM Equity 8.127579
SAN SM Equity 4.521443
ISP IM Equity 5.023080
SX7E Index 4.900426
ANZ AU Equity 0.723205
CSGN VX Equity -0.800900
SWEDA SS Equity -0.973182
POP SM Equity 4.434381
BNP FP Equity 3.378214
BARC LN Equity -0.066818
Name: Vol_Adj_10, dtype: float64
我使用以下代码在Plotly(https://plot.ly/~dpsugasa/289/_10-day-volatility-adjusted-returns/)中创建了一个图:
ten_day.iplot(kind='barh', bargap=.2, filename = 'Vol_Adjusted/Bank Returns/10Day_Vol_Adjusted',\
title='10 Day Volatility Adjusted Returns', legend = True,
xTitle = '10D Vol Adjusted Return (30D)', vline ={'x':'0','color':'black','width':'2'}, sortbars=True,
margin = (200,5))
我希望负条与正条的颜色不同。有没有办法只使用袖扣来做到这一点?
我考虑使用ten_day.loc[lambda df: df>0]
过滤正值和负值,然后尝试绘制两条不同的曲线,但我正在努力使语法正确。任何帮助将不胜感激。
答案 0 :(得分:1)
如果没有@echo off
color 0E
pushd %~dp0
setlocal EnableDelayedExpansion
for /f "usebackq tokens=*" %%i in ("%~dp0hostnames.txt") do (
rem Test Access Admin Shares C$
if exist "\\%%i\C$\Windows\System32" set dollar=yes
rem Test Installation Integrity
if exist "\\%%i\C$\ProgramData\config.cfg" set install=ok
echo %%i
echo !dollar!
echo !install!
pause
IF !dollar!==yes IF !install!==ok (call :updatecfg %%i)
IF !dollar!==yes IF [!install!]==[] (call :installerror %%i)
IF [!dollar!]==[] (call :errorshare %%i)
)
echo THE END
pause
exit
:updatecfg
CLS
XCOPY "%~dp0config.cfg" /Y "\\%1\C$\ProgramData" & echo %1 Update Config.cfg Succeeded! & echo %1 Update Succeeded! >>"%~dp0logpass.txt"
ping 127.0.0.1 -n 3 >nul
goto :eof
:errorshare
CLS
echo.
echo %1 Has C$ Access Issues [Logging] & echo %1 Has C$ Access Issues >>"%~dp0logfail.txt"
ping 127.0.0.1 -n 3 >nul
goto :eof
:installerror
CLS
echo.
echo %1 Cannot Find Config.cfg^!^! [Logging] & echo %1 Cannot Find Config.cfg^!^! Not Installed or Configured^? >>"%~dp0logfail.txt"
ping 127.0.0.1 -n 4 >nul
goto :eof
,我们可以将一系列颜色传递给条形图
cufflinks
但是bar = plotly.graph_objs.Bar(y=df[3], marker=dict(color=np.where(df[3] > 0, 'green', 'red').tolist()))
fig = plotly.graph_objs.Figure(data=[bar])
plotly.offline.plot(fig)
似乎忽略了这样一个列表。所以我们需要传递两种不同颜色的不同列。
cufflinks
完整代码
pd.DataFrame(dict(pos=df[df[3] > 0][3],
neg=df[df[3] <= 0][3])).iplot(kind='barh',
colors=dict(pos='green',
neg='red')
)