Close Navigation
Learn more about IBKR accounts
Plotly Python – An Interactive Data Visualization – Part II

Plotly Python – An Interactive Data Visualization – Part II

Posted May 12, 2020
Rekhit Pachanekar and Shaktiprasad Shimpi

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 =‘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’),
# 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

The scatter plot is given below:

Plotly Python – An Interactive Data Visualization

To interact with the Chart and download the code, visit QuantInsti: To edit Plotly code in the charts, visit

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

Disclosure: Interactive Brokers

Information posted on IBKR Campus that is provided by third-parties does NOT constitute a recommendation that you should contract for the services of that third party. Third-party participants who contribute to IBKR Campus 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 its permission. The views expressed in this material are solely those of the author and/or QuantInsti and Interactive Brokers 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 buy or sell any security. It should not be construed as research or investment advice or a recommendation to buy, sell or hold any security or commodity. 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.

IBKR Campus Newsletters

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.