Logo
AXION

Python SDK Visualizations

Visualization Methods

A collection of visualization functions for financial and data analysis using Plotly.js. These methods provide interactive charts and graphs for data exploration and presentation.

visualize (Core Helper)

HELPERvisualize.visualize(fig)

Displays a Plotly figure object. This is the core visualization function used internally by all other methods. In Jupyter notebooks, this will render the chart inline. In scripts, it will open the chart in a browser.

Parameters

ParameterTypeRequiredDescription
figplotly.graph_objects.FigureRequiredPlotly figure object to display
|

Example

# Create a simple figure
import plotly.graph_objects as go
fig = go.Figure(data=go.Scatter(x=[1,2,3], y=[4,5,6]))

# Display it
visualize.visualize(fig)

visualize.cov()

FUNCTIONvisualize.cov(df)

Creates a heatmap visualization of the correlation matrix for numeric columns in a DataFrame. Uses the Viridis color scale and automatically handles the correlation calculation.

Parameters

ParameterTypeRequiredDescription
dfpandas.DataFrameRequiredDataFrame containing numeric columns for correlation analysis. Non-numeric columns are automatically ignored.
|

Example

import pandas as pd
from axion import visualize

# Create sample data
df = pd.DataFrame({
    'A': [1, 2, 3, 4, 5],
    'B': [2, 4, 6, 8, 10],
    'C': [5, 4, 3, 2, 1],
    'D': [1, 3, 5, 7, 9]
})

# Display correlation heatmap
visualize.cov(df)

visualize.candles()

FUNCTIONvisualize.candles(df)

Creates an interactive candlestick chart for financial price data with OHLC (Open, High, Low, Close) values. Perfect for stock prices, cryptocurrency data, or any time-series financial data.

Required DataFrame Columns

  • time - Time series data (dates/timestamps)
  • open - Opening price for each period
  • high - Highest price during each period
  • low - Lowest price during each period
  • close - Closing price for each period
|

Example

import pandas as pd
from axion import visualize

# Sample stock data
df = pd.DataFrame({
    'time': ['2024-01-01', '2024-01-02', '2024-01-03'],
    'open': [100, 102, 101],
    'high': [105, 103, 104],
    'low': [99, 101, 100],
    'close': [102, 101, 103]
})

# Display candlestick chart
visualize.candles(df)

visualize.line()

FUNCTIONvisualize.line(df, x, y, log=False)

Creates a line chart for time series or sequential data visualization. Supports logarithmic scaling for the x-axis.

Parameters

ParameterTypeDefaultDescription
dfpandas.DataFrame-DataFrame containing the data to plot
xstring-Column name for x-axis values (typically time/date)
ystring-Column name for y-axis values
logbooleanFalseUse logarithmic scale for x-axis
|

Examples

Basic Line Chart

# Basic line chart
df = pd.DataFrame({
    'date': ['2024-01-01', '2024-01-02', '2024-01-03'],
    'value': [10, 15, 13]
})
visualize.line(df, x='date', y='value')

Logarithmic X-Axis

# Line chart with logarithmic x-axis
df = pd.DataFrame({
    'x': [1, 10, 100, 1000],
    'y': [1, 2, 3, 4]
})
visualize.line(df, x='x', y='y', log=True)

visualize.pie()

FUNCTIONvisualize.pie(df, values, labels)

Creates a pie chart showing proportional distribution of categorical data. Each slice represents a category, and the size corresponds to the numeric values.

Parameters

ParameterTypeRequiredDescription
dfpandas.DataFrameRequiredDataFrame containing the data
valuesstringRequiredColumn name for pie slice sizes (numeric)
labelsstringRequiredColumn name for pie slice labels (categorical)
|

Example

# Market share data
df = pd.DataFrame({
    'company': ['Apple', 'Samsung', 'Google', 'Others'],
    'market_share': [45, 30, 15, 10]
})

visualize.pie(df, values='market_share', labels='company')

visualize.fit()

FUNCTIONvisualize.fit(df, x, y, log=False, hover=[], group=None)

Creates a scatter plot with an Ordinary Least Squares (OLS) trendline for regression analysis. The trendline shows the linear relationship between variables with confidence bands.

Parameters

ParameterTypeDefaultDescription
dfpandas.DataFrame-DataFrame containing the data
xstring-Column name for x-axis values (independent variable)
ystring-Column name for y-axis values (dependent variable)
logbooleanFalseUse logarithmic scale for x-axis
hoverlist[]List of column names to show in hover tooltips
groupstringNoneColumn name for color grouping (creates separate trendlines per group)
|

Examples

With Grouping

# Simple linear regression
df = pd.DataFrame({
    'x': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
    'y': [2, 4, 5, 4, 5, 7, 8, 9, 10, 12],
    'category': ['A', 'A', 'A', 'A', 'B', 'B', 'B', 'B', 'B', 'B']
})

# With grouping
visualize.fit(df, x='x', y='y', group='category', hover=['category'])

# Without grouping
visualize.fit(df, x='x', y='y')

visualize.scatter()

FUNCTIONvisualize.scatter(df, x, y, log=False, hover=[], group=None)

Creates a standard scatter plot for visualizing relationships between two variables. Supports grouping and hover data for enhanced data exploration.

Parameters

ParameterTypeDefaultDescription
dfpandas.DataFrame-DataFrame containing the data
xstring-Column name for x-axis values
ystring-Column name for y-axis values
logbooleanFalseUse logarithmic scale for x-axis
hoverlist[]List of column names to show in hover tooltips
groupstringNoneColumn name for color grouping
|

Examples

With Grouping

# Scatter plot with grouping and hover data
df = pd.DataFrame({
    'height': [150, 160, 170, 180, 155, 165, 175, 185],
    'weight': [50, 60, 70, 80, 55, 65, 75, 85],
    'gender': ['F', 'F', 'M', 'M', 'F', 'F', 'M', 'M'],
    'age': [25, 30, 35, 40, 28, 33, 38, 43]
})

visualize.scatter(df, x='height', y='weight', 
                  group='gender', hover=['age'])

Simple Scatter

# Simple scatter
visualize.scatter(df, x='height', y='weight')

visualize.bar()

FUNCTIONvisualize.bar(df, x, y)

Creates a vertical bar chart for categorical data comparison. Each bar represents a category, and the height represents the corresponding value.

Parameters

ParameterTypeRequiredDescription
dfpandas.DataFrameRequiredDataFrame containing the data
xstringRequiredColumn name for categories (x-axis)
ystringRequiredColumn name for values (bar heights)
|

Example

# Sales by product
df = pd.DataFrame({
    'product': ['A', 'B', 'C', 'D'],
    'sales': [1500, 2300, 1200, 3100]
})

visualize.bar(df, x='product', y='sales')

visualize.area()

FUNCTIONvisualize.area(df, x, y, group, sub="")

Creates a stacked area chart showing cumulative values over time by category. Great for visualizing composition changes over time.

Parameters

ParameterTypeDefaultDescription
dfpandas.DataFrame-DataFrame containing the data
xstring-Column name for x-axis (typically time/date)
ystring-Column name for y-axis values
groupstring-Column name for grouping/categories
substring""Subgroup identifier (currently unused)
|

Example

# Monthly sales by region
df = pd.DataFrame({
    'month': ['Jan', 'Jan', 'Feb', 'Feb', 'Mar', 'Mar'],
    'sales': [100, 150, 120, 180, 140, 200],
    'region': ['North', 'South', 'North', 'South', 'North', 'South']
})

visualize.area(df, x='month', y='sales', group='region')

visualize.heatmap()

FUNCTIONvisualize.heatmap(df, x, y, hover=[])

Creates a density heatmap showing the distribution of data points across two dimensions. The color intensity represents the density of points in each region.

Parameters

ParameterTypeDefaultDescription
dfpandas.DataFrame-DataFrame containing the data
xstring-Column name for x-axis values
ystring-Column name for y-axis values
hoverlist[]List of column names to show in hover tooltips
|

Example

# Create sample data with clusters
import numpy as np
import SEOMetadata from '@/components/SEOMetadata';
np.random.seed(42)
df = pd.DataFrame({
    'x': np.random.normal(0, 1, 1000),
    'y': np.random.normal(0, 1, 1000),
    'value': np.random.randn(1000)
})

visualize.heatmap(df, x='x', y='y', hover=['value'])

visualize.radar()

FUNCTIONvisualize.radar(df, values, labels)

Creates a radar chart for multivariate data visualization across multiple axes. Each axis represents a different variable, and the area shows the profile.

Parameters

ParameterTypeRequiredDescription
dfpandas.DataFrameRequiredDataFrame containing a single row of data
valuesstringRequiredColumn name containing the numeric values
labelsstringRequiredColumn name containing the axis labels
|

Example

# Product performance metrics
df = pd.DataFrame({
    'metric': ['Speed', 'Reliability', 'Cost', 'Quality', 'Support'],
    'score': [85, 92, 78, 95, 88]
})

visualize.radar(df, values='score', labels='metric')

visualize.barh()

FUNCTIONvisualize.barh(df, x, y)

Creates a horizontal bar chart, useful for comparing categories with long names or when you have many categories. Bars extend horizontally from the y-axis.

Parameters

ParameterTypeRequiredDescription
dfpandas.DataFrameRequiredDataFrame containing the data
xstringRequiredColumn name for values (bar lengths)
ystringRequiredColumn name for categories (y-axis labels)
|

Example

# Long category names
df = pd.DataFrame({
    'product': ['Enterprise License', 'Professional Edition', 
                'Standard Package', 'Basic Subscription'],
    'revenue': [150000, 85000, 45000, 20000]
})

visualize.barh(df, x='revenue', y='product')

visualize.spread()

FUNCTIONvisualize.spread(dfs, x, y)

Creates a composite chart showing two series and their difference (spread) as a bar chart. Perfect for pairs trading analysis or comparing two related time series.

Parameters

ParameterTypeRequiredDescription
dfslist of DataFramesRequiredList containing two DataFrames to compare
xstringRequiredCommon column name for merging and x-axis (usually time/date)
ystringRequiredColumn name for values in both DataFrames
|

Example

# Compare two correlated stocks
df1 = pd.DataFrame({
    'date': ['2024-01-01', '2024-01-02', '2024-01-03'],
    'price': [100, 102, 101]
})

df2 = pd.DataFrame({
    'date': ['2024-01-01', '2024-01-02', '2024-01-03'],
    'price': [98, 101, 103]
})

visualize.spread([df1, df2], x='date', y='price')

visualize.polls()

FUNCTIONvisualize.polls(df)

Creates a multi-line chart where each column in the DataFrame becomes a separate line series. The x-axis uses the DataFrame index, making it ideal for time series with multiple variables.

Parameters

ParameterTypeRequiredDescription
dfpandas.DataFrameRequiredDataFrame where each column becomes a line series. Index is used for x-axis.
|

Example

# Opinion polling over time
df = pd.DataFrame({
    'Candidate A': [45, 47, 46, 48, 50, 49],
    'Candidate B': [42, 41, 43, 42, 41, 43],
    'Undecided': [13, 12, 11, 10, 9, 8]
}, index=['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'])

visualize.polls(df)

visualize.tree()

FUNCTIONvisualize.tree(df)

Creates a hierarchical treemap visualization for nested categorical data. Rectangles represent hierarchy levels, with size proportional to marketCap and color indicating pctchange.

Expected DataFrame Columns

  • sector - Top-level category (e.g., Technology, Healthcare)
  • industry - Mid-level category (e.g., Software, Biotech)
  • symbol - Leaf-level identifier (e.g., AAPL, MSFT)
  • marketCap - Size value (determines rectangle area)
  • pctchange - Color/hover data (red-green color scale)
  • lastsale - Additional hover data (last sale price)
|

Example

# Stock market sector visualization
df = pd.DataFrame({
    'sector': ['Tech', 'Tech', 'Tech', 'Health', 'Health'],
    'industry': ['Software', 'Software', 'Hardware', 'Biotech', 'Pharma'],
    'symbol': ['AAPL', 'MSFT', 'NVDA', 'GILD', 'PFE'],
    'marketCap': [2500000, 2100000, 800000, 700000, 180000],
    'pctchange': [2.5, 1.8, -0.5, 3.2, -1.1],
    'lastsale': [175.50, 380.25, 450.75, 85.30, 42.60]
})

visualize.tree(df)

visualize.graph()

FUNCTIONvisualize.graph(df, x, bars=[], lines=[], areas=[], title='', color=None)

Creates a comprehensive composite chart combining bars, lines, and areas on the same plot. Offers maximum flexibility for complex visualizations with multiple series types.

Parameters

ParameterTypeDefaultDescription
dfpandas.DataFrame-DataFrame containing all data
xstring-Column name for x-axis values
barslist[]List of column names for bar series
lineslist[]List of column names for line series
areaslist[]List of column names for area series
titlestring''Chart title
colorstringNoneColumn name for color grouping bars

Color Palette

shades_of_white = [
    'rgb(31, 119, 180)',  // blue
    'rgb(255, 127, 14)',  // orange
    'rgb(44, 160, 44)',   // green
    'rgb(214, 39, 40)',   // red
    'rgb(148, 103, 189)', // purple
    'rgb(140, 86, 75)',   // brown
    'rgb(255, 255, 255)',
    'rgb(245, 245, 245)',
    'rgb(235, 235, 235)',
    'rgb(235, 225, 225)',
    'rgb(235, 215, 215)',
    'rgb(235, 205, 205)',
]
|

Examples

Composite Chart

# Composite chart with bars and lines
df = pd.DataFrame({
    'date': ['2024-01-01', '2024-01-02', '2024-01-03'],
    'revenue': [1000, 1200, 1100],
    'profit': [200, 250, 230],
    'users': [500, 600, 650],
    'region': ['North', 'South', 'North']
})

visualize.graph(df, x='date', 
                bars=['revenue'], 
                lines=['profit', 'users'],
                title='Company Performance')

With Color Grouping

# With color grouping for bars
visualize.graph(df, x='date', 
                bars=['revenue'], 
                lines=['profit'],
                color='region',
                title='Performance by Region')