I'm trying to set up a financial chart in Conda Pycharm IDE using Plotly Express, but for some reason I'm not able to run the script in Pycharm since the graph keeps opening in my chrome browser instead. I have already installed conda in the terminal, but it still doesn't open the chart internally in the IDE. The chart is only extracting 'date' and 'close' values from the API Key. This is the data (you can just web scrape the latest 1000 data points from yahoo finance and you will get the exact same numbers):
The code is as follows:
import requests #for http request to Marketstack.com
import pandas as pd
import numpy as np
# Api Key
params = {
'access_key': '*************************'
}
# Request Api Key Data
api_result = requests.get('https://api.marketstack.com/v1/eod?access_key=**********************&symbols=FB&sort=DESC&limit=1000', params)
api_response = api_result.json()
# Sorts the data into a table
df = pd.DataFrame(api_response['data'])
print(df)
# Exports and then imports csv data
df.to_csv('Test_Sample.csv', index=False)
dataframe = pd.read_csv('Test_Sample.csv', header=0)
# Reverse data table
dataframe2 = dataframe.iloc[::-1]
print(dataframe2)
# Convert string to floats
dataframe2['symbol']=dataframe2['symbol'].astype(str)
dataframe2['exchange']=dataframe2['exchange'].astype(str)
dataframe2['date']=dataframe2['date'].astype(str)
#dataframe2['symbol']=pd.to_numeric(dataframe2['symbol'], errors='coerce')
#dataframe2['exchange']=pd.to_numeric(dataframe2['exchange'], errors='coerce')
#dataframe2['date']=pd.to_numeric(dataframe2['date'], errors='coerce')
# Change X-axis to a series of integers
dataframe2.index=pd.to_numeric(np.arange(len(dataframe2)))
print(dataframe2)
# Convert date string to datetime index:
dataframe2.index = pd.DatetimeIndex(df['date'])
data=dataframe2
#data = dataframe2.iloc[::-1]
#aapl_df.index = pd.DatetimeIndex(df['date'].values) #Alternative pseudocode
import plotly.express as px
#import plotly.io as pio
#pio.renderers.default= 'svg'
#gapminder = px.data.gapminder()
fig = px.line(data, x='date', y='close', title='Financial Instrument')
for template in["plotly_dark"]:
fig.update_xaxes(
rangeslider_visible=True,
rangeselector=dict(
buttons=list([
dict(count=1, label="1m", step="month", stepmode="backward"),
dict(count=6, label="6m", step="month", stepmode="backward"),
dict(count=1, label="YTD", step="year", stepmode="todate"),
dict(count=1, label="1y", step="year", stepmode="backward"),
dict(step="all")
])
)
)
fig.show()
#fig.show(renderer="svg")