Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

matplotlib show() not working. chart windows opens for 1second and closes automatically

I’m trying to plot a chart using matplotlib in python 3.10.5 but as soon as i run my code it generated the chart in a new windows and closes within seconds.

Here is my function:

def plot_all(levels, df):    
  fig, ax = plt.subplots(figsize=(16, 9))   
  candlestick_ohlc(ax,df.values,width=0.6, colorup='green', 
    colordown='red', alpha=0.8)    
  date_format = mpl_dates.DateFormatter('%d %b %Y')
  ax.xaxis.set_major_formatter(date_format)    
  for level in levels:        
    plt.hlines(level[1], xmin = df['Date'][level[0]], 
    xmax = 
      max(df['Date']), colors='blue', linestyle='--')    
  fig.show()

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

As per the original docs of matplotlib and issues raised on GitHub https://github.com/Eomys/pyleecan/issues/311
it has been found that you are supposed to use plt.show() for the output to stay.
Simply, replace your fig.show() with plt.show().

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading