python - Volume Overlay with Pandas -
i see in context of matplotlib , open-high-low-close, i'm wondering if can add volume overlay within pandas framework. final graph want close first 1 here: (matplotlib - finance volume overlay )
say have dataframe such:
num rolling_30 rolling_10 rolling_60 volume date 2015-06-23 0.000219 0.000149 0.000168 0.000183 2 2015-06-25 0.000489 0.000162 0.000200 0.000188 3 2015-07-01 0.000164 0.000163 0.000190 0.000186 1 2015-07-02 0.000190 0.000166 0.000190 0.000187 1 2015-07-03 0.000269 0.000171 0.000198 0.000180 1 2015-07-04 0.000935 0.000196 0.000282 0.000193 2 2015-07-08 0.000154 0.000196 0.000288 0.000188 1 2015-07-11 0.000274 0.000202 0.000305 0.000190 1 2015-07-13 0.000872 0.000228 0.000380 0.000201 9
how can ['num','rolling_30','rolling_10','rolling_60'] line chart bottom of chart listing daily volume? can secondary_y volume on right, looks terrible. need traditional volume bar-graph @ bottom of chart.
the basic idea use .twinx
create secondary y axis. below short sample it. graph, see left y axis price , moving averages, whereas right y axis volumn.
import pandas pd import matplotlib.pyplot plt # data # ============================ print(df) num rolling_30 rolling_10, rolling_60 volume date 2015-06-23 0.0002 0.0001 0.0002 0.0002 2 2015-06-25 0.0005 0.0002 0.0002 0.0002 3 2015-07-01 0.0002 0.0002 0.0002 0.0002 1 2015-07-02 0.0002 0.0002 0.0002 0.0002 1 2015-07-03 0.0003 0.0002 0.0002 0.0002 1 2015-07-04 0.0009 0.0002 0.0003 0.0002 2 2015-07-08 0.0002 0.0002 0.0003 0.0002 1 2015-07-11 0.0003 0.0002 0.0003 0.0002 1 2015-07-13 0.0009 0.0002 0.0004 0.0002 9 # plotting # =========================== fig, ax = plt.subplots(figsize=(10,8)) df.drop('volume', axis=1).plot(ax=ax) ax.legend(loc='best') ax2 = ax.twinx() df['volume'].plot(kind='bar', ax=ax2, color='g', alpha=0.1) ax2.set_ylim([0, ax2.get_ylim()[1] * 10]) ax2.legend(loc='best')
Comments
Post a Comment