This website uses cookies to collect usage information in order to offer a better browsing experience. By browsing this site or by clicking on the "ACCEPT COOKIES" button you accept our Cookie Policy.

Plotly Python – An Interactive Data Visualization – Part II

See Part I to get started with Plotly Python.

Scatter Plot

Usually, a scatter plot is used as a visual of the correlation between two entities. Here, we will try to see if there is any correlation between the Adjusted Closing prices of Tesla and Apple, respectively.

Since we had used the data of Tesla from 1 February to 3 March. We will import the data of the same time frame.

Thus, the Python code for importing the Apple data is as follows:

# Import Apple data
apple = yf.download(‘AAPL’,’2020-02-01′, ‘2020-03-03’)

Now, we will calculate the percentage change of both Tesla and Apple and store it in a new column as “Percentage Change”

# Calculate Daily Percentage Change
tesla[‘PercentChange’]=tesla[‘Adj Close’].pct_change()
apple[‘PercentChange’]=apple[‘Adj Close’].pct_change()
# Create Layout
layout = go.Layout(title = ‘Tesla Vs Apple Chart’,
xaxis = dict (title = ‘Tesla Percent change’),
yaxis = dict (title = ‘Apple Percent change’),
hovermode=’closest’)
# Create Data to Plot
data = [go.Scatter(x = tesla[‘PercentChange’],y = apple[‘PercentChange’], mode=’markers’)]
# Create Figure Object
figure = go.Figure(data=data,layout=layout)
# Plot the figure
figure.show()

The scatter plot is given below:

Plotly Python – An Interactive Data Visualization

To interact with the Chart and download the code, visit QuantInsti: https://blog.quantinsti.com/plotly-python/. To edit Plotly code in the charts, visit https://chart-studio.plot.ly/create/?fid=Quantra_Content:1#/

In the next installment of this series, the authors will discuss Line Chart using Plotly Express.

Disclosure: Interactive Brokers

Information posted on IBKR Traders’ Insight that is provided by third-parties and not by Interactive Brokers does NOT constitute a recommendation by Interactive Brokers that you should contract for the services of that third party. Third-party participants who contribute to IBKR Traders’ Insight are independent of Interactive Brokers and Interactive Brokers does not make any representations or warranties concerning the services offered, their past or future performance, or the accuracy of the information provided by the third party. Past performance is no guarantee of future results.

This material is from QuantInsti and is being posted with permission from QuantInsti. The views expressed in this material are solely those of the author and/or QuantInsti and IBKR is not endorsing or recommending any investment or trading discussed in the material. This material is not and should not be construed as an offer to sell or the solicitation of an offer to buy any security. To the extent that this material discusses general market activity, industry or sector trends or other broad based economic or political conditions, it should not be construed as research or investment advice. To the extent that it includes references to specific securities, commodities, currencies, or other instruments, those references do not constitute a recommendation to buy, sell or hold such security. This material does not and is not intended to take into account the particular financial conditions, investment objectives or requirements of individual customers. Before acting on this material, you should consider whether it is suitable for your particular circumstances and, as necessary, seek professional advice.

trading top