0

I am using the following code to plot a bar graph using bar graph. It is a pandas dataframe of stock prices and indicator values. I am seeing a gap in my plot which are market close hours but my dataframe does not have rows for those market close hours. After the last data point of the day next data point starts at next day's open.

Here's the code:

df_final = df_supp.iloc[-100:]
df_final.dropna(inplace=True)
df_final['DateTime'] = df_final.index
x_axis =df_final['DateTime']
plt.figure(figsize=(18,6))
plt.bar(x_axis, df_final['wvf_support'], color=['lime' if x=='lime' else 'gray' for x in df_final['wvf_support_signal']], align='center', width=.005)
plt.show()

And here is the output I see:

Bar Graph of the indicator I wanna plot:

Please help me remove this unnecessary gap. Thanks!

  • 3
    That's just the nature of matplotlib when working with a timeseries graph, it interpolates a continuous time for the x-axis. A work around would be to replace the datetime values with strings or int values and then manually create tick labels for them, [similar to this answer](https://stackoverflow.com/a/65836503/4458369). Found in that same question is the use of [mplfinance function](https://stackoverflow.com/a/69623239/4458369) that turns off non-trading hours. – Michael S. Aug 02 '23 at 14:05
  • This helps. Thanks! – Anurag Agrawal Aug 02 '23 at 15:23

0 Answers0