Skip to main content

`fsplot` is a Python library for lightweight visualization of financial market data using SVG.

Project description

fs-plot

fsplot is a Python library for lightweight visualization of financial market data using SVG. It provides functions to generate SVG charts, making it ideal for web and mobile applications that require efficient and compact chart rendering.

Installation

To install fsplot, you can use pip. Run the following command:

pip install fsplot

Use Case

fsplot is good for scenarios where you need SVG or lightweight chart visualization for static financial market data in web or mobile applications. Using SVG instead of a data visualization library will result in a chart that is extremely lightweight in both rendering and file size.

Example Use

Here are some examples of how to use fsplot:

Fetching Example Data

import pandas as pd
import yfinance as yf

# Set the start and end dates
start_date = "2024-01-01"
end_date = "2024-09-01"

# Fetch Bitcoin data from Yahoo Finance
bitcoin = yf.download('BTC-USD', start=start_date, end=end_date)

# Ensure that the index is a DatetimeIndex
bitcoin.index = pd.to_datetime(bitcoin.index)

# Resample the data to a 2-day frequency and aggregate OHLC values
bitcoin = bitcoin.resample('3D').agg({
    'Open': 'first',
    'High': 'max',
    'Low': 'min',
    'Close': 'last'
})[-60:]

Plotting a Line Chart

from fsplot import plot_line

# Prepare data for plotting
data = bitcoin["Close"][-60:]

# Generate and display the candlestick plot
svg = plot_line(data)

with open("line.svg", "w") as file:
    file.write(svg)

Output:

Line Plot

Plotting a Candlestick Chart

from fsplot import plot_candlestick

# Prepare data for plotting
data = {
    "Open": bitcoin["Open"],
    "High": bitcoin["High"],
    "Low": bitcoin["Low"],
    "Close": bitcoin["Close"]
}

# Generate and display the candlestick plot
svg = plot_candlestick(data)

with open("candlestick.svg", "w") as file:
    file.write(svg)

Output:

Candlestick Plot

Plotting a Candlestick Chart with Trendline

from trendline import calculate_trendline
from fsplot import plot_candlestick_trendline

# Calculate trendline
trend_line = calculate_trendline(bitcoin)


# Prepare data for plotting
data = {
    "Open": bitcoin["Open"],
    "High": bitcoin["High"],
    "Low": bitcoin["Low"],
    "Close": bitcoin["Close"],
    "support_first_value": trend_line["support_first_value"],
    "support_gradient": trend_line["support_gradient"],
    "resistance_first_value": trend_line["resistance_first_value"],
    "resistance_gradient": trend_line["resistance_gradient"]
}

# Generate and display the candlestick plot
svg = plot_candlestick_trendline(data)

with open("candlestick_trendline.svg", "w") as file:
    file.write(svg)

Output:

Candlestick Plot with Trendline

Project details


Release history Release notifications | RSS feed

This version

0.2

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fsplot-0.2.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fsplot-0.2-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file fsplot-0.2.tar.gz.

File metadata

  • Download URL: fsplot-0.2.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.8.0

File hashes

Hashes for fsplot-0.2.tar.gz
Algorithm Hash digest
SHA256 ca95bcc865028968fcb3b685aa38133472bf52cb70118067887cda0090bf6e95
MD5 b028af993120bce5e7e7397c961aacf9
BLAKE2b-256 8eed112b37e37a3b7cd3d8e96d586cfe94bb1f9c5512ded49fc3c98bb1248324

See more details on using hashes here.

File details

Details for the file fsplot-0.2-py3-none-any.whl.

File metadata

  • Download URL: fsplot-0.2-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.8.0

File hashes

Hashes for fsplot-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5e7a87784de3ee054103e92e4d64d1f4ee2180938891d2011f2ef474c5125808
MD5 489c422ce6b3164447ea0bf9bb084009
BLAKE2b-256 4d6b6367a471179ac8c781be0d28c6828e65f0535dc8ec7afd047bec0fe8100c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page