Skip to content

LSEG-API-Samples/Article.DataLibrary.Python.PlotlyChart

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Plotting Financial Data Chart with Plotly Python

  • Last update: March 2025
  • Environment: Windows
  • Compiler: Python
  • Prerequisite: Workspace application with access to Data Library

Overview

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.

Introduction to Plotly Python

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()

Figure-1

Introduction to the Data Library for Python

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.

Figure-2

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:

Disclaimer

This project is based on Data Library Python versions 2.0.1 using the Desktop Session only.

Prerequisite

This example requires the following dependencies software and libraries.

  1. LSEG Workspace application with access to Data Library.
  2. Python version 3.10 or 3.11 (Command or MiniConda distribution/package manager can be used as well).
  3. JupyterLab application.
  4. 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.

Application Files

This example project contains the following files and folders

  1. notebook/plotly_ld.ipynb: The example JupyterLap application file.
  2. requirements.txt: The project dependencies configuration file.
  3. images: Project images folder.
  4. LICENSE.md: Project's license file.
  5. README.md: Project's README file.

How to run this example with the Classic Jupyter Notebook

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.

  1. Open a Command Prompt and go to the project's folder

  2. 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
  3. Once the environment is created, activate an environment named plotly_chart with this command in a Command Prompt.

    $>plotly_chart\Scripts\activate
  4. 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
  5. 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!"
                }
            }
        }
    }
  6. 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
  7. JupyterLab will open the web browser and will go to the notebook home page.

  8. Open the plotly_ld.ipynb.ipynb Notebook document, then go through each notebook cell.

    Figure-3

How to run this example with the CodeBook

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:

  1. In the Workspace application, search for the CodeBook (or CODEBK).

    Figure-4

  2. Once the CodeBook finished initialize, create a new folder name plotly

    Figure-5

    Figure-6

  3. Enter the plotly folder, and click the upload button and select plotly_ld.ipynb.ipynb notebook file.

    Figure-7

  4. Then open the plotly_ld.ipynb.ipynb notebook file

    Figure-8

  5. On this init session cell, change it to

    # CodeBook
    ld.open_session()

    Figure-9

Conclusion

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:

Pros

  1. Use a few lines of code to create and customize the graph.
  2. Provide more than 30 ease-of-use various chart object types for Developers.
  3. Experience Developers can use the low-level chart object types to create a more powerful and flexible chart.
  4. Simplify documents and example code.
  5. Provide a dedicated paid support program for both individual and corporate developers.

Cons

  1. Some API Interface and installation processes for Classic Jupyter Notebook and Jupyter Lab are different.
  2. 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.
  3. 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.

References

You can find more detail regarding the Plotly, Data Library, and related technologies from the following resources:

For any question related to this example or Data Library, please use the Developers Community Q&A Forum.

About

This repository demonstrate how to use Plotly Python library to plot chart on IPython environment.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published