- Last update: March 2025
- Environment: Windows
- Compiler: Python
- Prerequisite: Workspace application with access to Data Library
With the rise of Data Scientists, Financial coders, or Traders (aka Citizen Developers), data visualization is a big part of how to present data, information, and its context to the readers (Financial team, Marketing team, etc.). The good data analysis itself cannot be used with a good graph representation.
The Matplotlib Pyplot is a de-facto library for making interactive plot and data visualization in the Python and Data Scientists world. However, the Matplotlib is a huge library that contains several interfaces, capabilities, and 1000+ pages of documents.
There are a lot of others alternative Plotting libraries such as Seaborn (which is a high-level interface of Matplotlib), Spotify's Chartify, Bokeh, Plotly Python, etc.
This example project demonstrates how to use the Plotly Python library to plot various types of graphs. The demo application uses data from LSEG Workspace platform via the LSEG Data Library for Python (Data Library version 2) as an example dataset.
Plotly Python is a free and open source interactive graphing library for Python. The library is built on top of plotly.js JavaScript library (GitHub). Both Plotly Python and Plotly JavaScript are part of Plotly's Dash and Chart Studio applications suites which provide interactively, scientific data visualization libraries/solutions for Data Scientists and Enterprise.
This Jupyter Notebook is focusing on the Plotly Python open-source library versions 6.0.1 and 5.4.0 (on CodeBook) only.
import plotly.express as px
fig = px.line(x=["a","b","c"], y=[1,3,2], title="sample figure")
fig.show()
The LSEG Data Library for Python (aka Data Library version 2) provides a set of ease-of-use interfaces offering coders uniform access to the breadth and depth of financial data and services available on the Workspace, RDP, and Real-Time Platforms. The API is designed to provide consistent access through multiple access channels and target both Professional Developers and Financial Coders. Developers can choose to access content from the desktop, through their deployed streaming services, or directly to the cloud. With the Data Library, the same Python code can be used to retrieve data regardless of which access point you choose to connect to the platform.
The Data Library are available in the following programming languages:
For more deep detail regarding the Data Library for Python, please refer to the following articles and tutorials:
This project is based on Data Library Python versions 2.0.1 using the Desktop Session only.
This example requires the following dependencies software and libraries.
- LSEG Workspace application with access to Data Library.
- Python version 3.10 or 3.11 (Command or MiniConda distribution/package manager can be used as well).
- JupyterLab application.
- Internet connection.
Please contact your LSEG's representative to help you to access Workspace credentials. You can generate/manage the AppKey by follow the steps in Data Library for Python Quick Start page.
This example project contains the following files and folders
- notebook/plotly_ld.ipynb: The example JupyterLap application file.
- requirements.txt: The project dependencies configuration file.
- images: Project images folder.
- LICENSE.md: Project's license file.
- README.md: Project's README file.
Please note that the Workspace application integrates a Data API proxy that acts as an interface between the Eikon Data API Python library and the Eikon Data Platform. For this reason, the Workspace application must be running when you use the Eikon Data API Python library.
The first step is to unzip or download the example project folder into a directory of your choice, then set up a Conda environment for running the application with the steps below.
-
Open a Command Prompt and go to the project's folder
-
Run the following command in a Command Prompt application to create the Python environment named plotly_chart for the project.
$>python -m venv plotly_chart
-
Once the environment is created, activate an environment named
plotly_chart
with this command in a Command Prompt.$>plotly_chart\Scripts\activate
-
Once an environment is activated, run the following command to install all dependencies in the plotly_chart environment
(plotly_chart) $>pip install -r requirements.txt
-
Go to project's notebook folder and input your Workspace App Key a file name
lseg-data.config.json
with the following content{ "logs": {...}, "sessions": { "default": "desktop.workspace", "desktop": { "workspace": { "app-key": "YOUR APP KEY GOES HERE!" } } } }
-
In a current Command Prompt, go to the project's notebook folder. Run the following command to start the JupyterLab application.
(plotly_chart) $>notebook>jupyter notebook
-
JupyterLab will open the web browser and will go to the notebook home page.
-
Open the plotly_ld.ipynb.ipynb Notebook document, then go through each notebook cell.
If you are Workspace user, you can access CodeBook, the cloud-hosted Jupyter Notebook development environment for Python scripting from the application. The CodeBook is natively available in Workspace as an app (no installation required!!), providing access to LSEG APIs that are already pre-installed on the cloud.
The CodeBook also contains Plotly version 5.4.0. You can upload the plotly_ld.ipynb.ipynb notebook application to the CodeBook with the following steps:
-
In the Workspace application, search for the
CodeBook
(orCODEBK
). -
Once the CodeBook finished initialize, create a new folder name plotly
-
Enter the plotly folder, and click the upload button and select plotly_ld.ipynb.ipynb notebook file.
-
Then open the plotly_ld.ipynb.ipynb notebook file
-
On this init session cell, change it to
# CodeBook ld.open_session()
Data visualization is the first impression of data analysis for the readers. Data Scientists, Financial coders, and Developers take time on the data visualization process longer than the time they use for getting the data. It means the data visualization/chart library need to be easy to use, flexible and have a good document.
Plotly Python provides both ease-of-use/high-level and low-level interface for supporting a wide range of Developers' skills. Developers can pick the Plotly Chart object (line, bar, scatter, candlestick, etc) that match their requirements, check the Plotly example code and community page to create a nice chart with readable and easy to maintain source code.
When compare to the Matplotlib-Pyplot (which is the main player in the Charting library), the Plotly advantages and disadvantages are the following:
- Use a few lines of code to create and customize the graph.
- Provide more than 30 ease-of-use various chart object types for Developers.
- Experience Developers can use the low-level chart object types to create a more powerful and flexible chart.
- Simplify documents and example code.
- Provide a dedicated paid support program for both individual and corporate developers.
- Some API Interface and installation processes for Classic Jupyter Notebook and Jupyter Lab are different.
- Matplotlib-Pyplot has larger users based on developer community websites (such as StackOverflow). It means a lot of Pyplot questions, problems will be easy to find the answers or solutions than Plotly.
- Matplotlib-Pyplot has larger documents, tutorials, step-by-step guide resources from both official and user-based websites.
At the same time, the Data Library for Python lets developers rapidly access Workspace data and our latest platform capabilities with a few lines of code that easy to understand and maintain.
You can find more detail regarding the Plotly, Data Library, and related technologies from the following resources:
- LSEG Data Library for Python on the LSEG Developer Community website.
- Essential Guide to the Data Libraries - Generations of Python library (EDAPI, RDP, RD, LD) article.
- Upgrade from using Eikon Data API to the Data library article.
- The Data Library for Python - Quick Reference Guide (Access layer) article.
- LSEG Data Library for Python and its Configuration Process article.
- Plotly Official page.
- Plotly Python page.
- Plotly GitHub page
- Plotly Express page
- Plotly Graph Objects page
- Creating and Updating Figures in Python page
- Plotly Figure API reference page
- 4 Reasons Why I’m Choosing Plotly as My Main Visualization Library
- Getting Fundamentals Company Geographic Sales Breakdown from Workspace with Data Library
For any question related to this example or Data Library, please use the Developers Community Q&A Forum.