The graph is not showing, tried with TSLA, JPM and AAPL. Please help

import pandas as pd
import numpy as np
import datetime as dt
import yfinance as yf
import matplotlib.pyplot as plt
import seaborn as sns
import plotly.express as px
import plotly.graph_objects as go  # Import plotly.graph_objects for using go.Figure



com_tckr=input("State the Ticker of the company you want to analyse:")
st_dt=input("Enter the starting date:")
end_dt=input("Enter the end date:")
com_df=yf.download(com_tckr, start=st_dt, end=end_dt, actions=True)
#checking for null or NaN values
num_null=com_df.isnull().sum()
print("The number of null or missing values in the downloaded data:",num_null)
#Calculate % daily returns
com_df['DailyReturns']=(com_df['Close'].pct_change(1)*100).round(2)
com_df['DailyReturns'].replace(np.nan,0,inplace=True)
print(com_df)
print()
#Calculate and print the maximum %daily return for the company
print(com_df.describe().round(2))

def plot_financial_data(df, title):
  fig=go.Figure() # Create a Figure object using go.Figure

  financial_columns = ['Open', 'High', 'Low', 'Close', 'Adj Close', 'Volume']
   financial_columns = [col for col in financial_columns if col in df.columns]

  for col in financial_columns: # Iterate over the list of financial column names
    fig.add_trace(go.Scatter(x=df.index, y=df[col], mode='lines', name=col)) # Use add_trace with go.Scatter
    fig.update_traces(line_width=2) # Adjust line width as needed

  fig.update_layout(
      title=title,
      xaxis_title="Date",
      yaxis_title="Value",
      plot_bgcolor="white"
  )
  fig.show()

option=input("Do you want graphical representation(y/n)?")
if(option=='y'):
  plot_financial_data(com_df, 'Financial Data')

Hello,

please re-enter your script per the instructions provided so that it appears as it does on your computer terminal. Here is an example:

# Example how script will appear
def some_function(x, y):
    print(f'{x} + {y} = {x + y}')

Giving your script a quick glance:

One quick point:

  1. You are overriding the original financial_columns list variable. Are you ok with this?

Please re-enter your script with the instructions provided. Ensure that it appears as it does on your terminal with all appropriate indentations. Please also provide any error exceptions that you observe when attempting to run your script.