我有以下数据帧:
symbol DAL MS QQQ SPY TLT XLE
symbol
DAL NaN NaN NaN NaN NaN NaN
MS 0.560979 NaN NaN NaN NaN NaN
QQQ 0.621045 0.789771 NaN NaN NaN NaN
SPY -0.576444 -0.843485 -0.953304 NaN NaN NaN
TLT 0.186840 0.421957 0.333320 -0.347808 NaN NaN
XLE 0.115093 0.578970 0.559711 -0.701126 0.38047 NaN
然后对数据帧进行堆叠和排序,并将结果绘制为条形图,如下所示:
^{pr2}$我现在要做的是(没有成功)不是把它画成条形图,而是通过填充零下和零上的区域来绘制它。我的猜测是我应该在类似于以下示例之间使用填充符:link:
ax.fill_between(dfstacked.index, 0, dfstacked.values, where = dfstacked.values > 0, interpolate=True)
ax.fill_between(dfstacked.index, dfstacked.values, 0, where = dfstacked.values < 0, interpolate=True)
我得到错误:TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
您可以使用
width
和edgecolor
参数来获得看起来不像直方图的内容。在你的语法有点不对劲。在您的例子中,
fill_between
需要X值,然后是要填充的Y值,然后是Y值。在下面是一个小例子:
然后您可以使用您的
index
来set_xticklabels
。在您尝试^{} :
然后从
^{pr2}$multiindex
设置axis x
:相关问题 更多 >
编程相关推荐