I’m going to walk you through the process of creating interactive and professional financial charts in Plotly with Python. Plotly is built on top of Python and enables data scientists to produce professional and great-looking plots with less-code. The categories of plots include basic charts, statistical charts, ML and AI charts, scientific charts, and financial charts.
One of the most popular packages used for interactive visualizations is Plotly. Plotly is built on top of python and enables data scientists to produce professional and great-looking plots with less-code. It became popular because of its extensive category of plots which can be produced in no-time. The categories of plots include basic charts, statistical charts, ML and AI charts, scientific charts, and financial charts.
In this article, I’m going to walk you through the process of creating interactive and professional financial charts in Plotly with python. We will also explore yahoo’s API for pulling historical stock data which we will be using for visualizations. Let’s get started!
Our primary packages include pandas for data processing, pandas DataReader for pulling the historical stock data, Datetime to deal with dates, finally, Plotly and its dependencies for interactive visualizations. Follow the code to import the primary packages into our python environment.
## Importing packages import pandas as pd import datetime as dt import pandas_datareader.data as web import plotly.express as px import plotly.graph_objects as go
Our next process is going to be pulling the historical stock data for visualizations using the pandas DataReader package.
For our visualizations, we are going to pull six companies’ historical data namely Facebook, Amazon, Apple, Netflix, Google, and Microsoft using yahoo’s API. Let’s pull the data in python!
## Data start = dt.datetime(2019,1,1) end = dt.datetime.now() stocks = web.DataReader(['FB','AMZN', 'AAPL', 'NFLX', 'GOOGL', 'MSFT'], 'yahoo', start, end) stocks_close = pd.DataFrame(web.DataReader(['FB','AMZN', 'AAPL', 'NFLX', 'GOOGL', 'MSFT'], 'yahoo', start, end)['Close'])
Firstly, we have defined two variables specifying the start and end date of our data. Next, using the pandas DataReader package, we have pulled the historical data of the companies. Finally, we stored only the close price data of companies in the ‘_stocks_close_’ variable. Now, we are ready to do visualizations on our stock data.
Often called ‘Mountain’ charts, area charts are a more simplified interpretation of standard line charts. They plot closing prices over a given period, and the area beneath the line is shaded. Follow the code to create an area chart with Plotly in python.
## Area chart area_chart = px.area(stocks_close.FB, title = 'FACEBOOK SHARE PRICE (2013-2020)') area_chart.update_xaxes(title_text = 'Date') area_chart.update_yaxes(title_text = 'FB Close Price', tickprefix = '$') area_chart.update_layout(showlegend = False) area_chart.show()
In the programming world, Data types play an important role. Each Variable is stored in different data types and responsible for various functions. Python had two different objects, and They are mutable and immutable objects.
Are you looking for experienced, reliable, and qualified Python developers? If yes, you have reached the right place. At **[HourlyDeveloper.io](https://hourlydeveloper.io/ "HourlyDeveloper.io")**, our full-stack Python development services...
🔥To access the slide deck used in this session for Free, click here: https://bit.ly/GetPDF_DataV_P 🔥 Great Learning brings you this live session on 'Data Vis...
Master Applied Data Science with Python and get noticed by the top Hiring Companies with IgmGuru's Data Science with Python Certification Program. Enroll Now
Looking to build robust, scalable, and dynamic responsive websites and applications in Python? At **[HourlyDeveloper.io](https://hourlydeveloper.io/ "HourlyDeveloper.io")**, we constantly endeavor to give you exactly what you need. If you need to...