A comprehensive visualization package for risk analysis with ridge plots, heatmaps, waterfall charts, time series tools, and advanced 2D/3D country mapping
Project description
RiskPlot
A comprehensive Python package for risk analysis visualization, featuring ridge plots, heatmaps, waterfall charts, network diagrams, globe visualizations, and surface plots.
🚀 Features
Core Visualizations
- Ridge Plots: Distribution comparisons across categories
- Heatmaps: Correlation matrices and risk matrices
- Waterfall Charts: Risk attribution and P&L decomposition
- Time Series: VaR tracking and drawdown analysis
Advanced Visualizations ✨
- Network Plots: Entity relationship networks (requires
networkx) - Geographic Maps: Professional 2D world maps and interactive 3D globes (requires
plotly) - Surface Plots: 2D/3D risk landscapes (requires
plotly,scipy)
🎯 Use Cases
- Financial Risk Management: Portfolio analysis, VaR calculations, stress testing
- Country Risk Analysis: Geographic risk assessment and monitoring
- Network Analysis: Financial interconnectedness, trade relationships
- Regulatory Reporting: Risk visualization for compliance and reporting
📦 Installation
Basic Installation
pip install riskplot
With Optional Dependencies
# For network visualizations
pip install riskplot[network]
# For globe visualizations
pip install riskplot[globe]
# For all features
pip install riskplot[all]
⚡ Quick Start
import riskplot
import pandas as pd
import numpy as np
# Create sample data
np.random.seed(42) # For reproducible results
returns_data = []
for portfolio, (mean, std) in [('Portfolio A', (0.05, 0.1)),
('Portfolio B', (0.03, 0.08)),
('Portfolio C', (0.07, 0.15))]:
returns = np.random.normal(mean, std, 100)
for ret in returns:
returns_data.append({'category': portfolio, 'returns': ret})
data = pd.DataFrame(returns_data)
# Ridge plot
fig, ax = riskplot.ridge_plot(data, 'category', 'returns')
# Correlation heatmap
correlation_matrix = pd.DataFrame(np.random.rand(5, 5))
fig, ax = riskplot.correlation_heatmap(correlation_matrix)
# Network visualization (requires networkx)
network_data = pd.DataFrame({
'source': ['A', 'B', 'C'],
'target': ['B', 'C', 'A'],
'weight': [0.8, 1.2, 0.5]
})
fig, ax = riskplot.country_interaction_network(network_data)
# 2D World Map (NEW - most common for reports)
country_data = pd.DataFrame({
'country': ['USA', 'CHN', 'GBR', 'DEU', 'JPN'],
'risk_score': [0.25, 0.65, 0.35, 0.20, 0.30]
})
fig = riskplot.country_choropleth_map(country_data,
country_col='country',
value_col='risk_score',
title='Global Risk Assessment')
fig.show()
# Interactive 3D globe (enhanced)
fig = riskplot.country_risk_globe(country_data,
country='country',
risk='risk_score')
fig.show()
Chart Types
Ridge Plots
# Basic ridge plot
rp.ridge_plot(data, 'category', 'value')
# Dual group comparison
rp.ridge_plot(data, 'category', 'value', 'group')
Heatmaps
# Correlation matrix
rp.correlation_heatmap(data)
# Risk matrix
rp.risk_matrix(data, 'probability', 'impact', 'label')
# Exposure heatmap
rp.exposure_heatmap(data, 'entity', 'sector', 'exposure')
Waterfall Charts
# Risk attribution
rp.risk_attribution_waterfall(data, 'factor', 'contribution')
# P&L waterfall
rp.pnl_waterfall(data, 'component', 'amount')
# VaR decomposition
rp.var_decomposition(data, 'component', 'var_contribution')
Geographic Visualization (NEW in v0.3.0)
# 2D Flat World Map - Perfect for reports and presentations
rp.country_choropleth_map(data, 'country', 'risk_score')
# 3D Interactive Globe - Engaging for stakeholder meetings
rp.country_risk_globe(data, 'country', 'risk_score')
# Regional Risk Heatmap - Compare regions and countries
rp.regional_risk_heatmap(data, 'region', 'country', 'risk_score')
Distribution Plots
# Violin plots
violin = rp.ViolinPlot()
fig, ax = violin.plot(data, 'category', 'value')
# Distribution summary
rp.risk_distribution_summary(data, 'returns')
Time Series
# Rolling risk metrics
rp.rolling_risk_metrics(data, 'date', 'returns')
# Drawdown analysis
drawdown = rp.DrawdownChart()
fig, axes = drawdown.plot(data, 'date', 'value', show_underwater=True)
Advanced Usage
Custom Configuration
config = rp.PlotConfig(
figsize=(12, 8),
colormap='plasma',
style='seaborn'
)
# Use with any visualization class
heatmap = rp.RiskHeatmap(config=config)
Extending the Framework
class CustomRiskPlot(rp.RiskVisualization):
def plot(self, data, **kwargs):
fig, ax = self._setup_figure(**kwargs)
# Your custom plotting logic
return fig, ax
Examples
examples/basic_usage.py- Basic functionality demonstrationexamples/recreate_original.py- Recreates original ridge plot exampleexamples/comprehensive_demo.py- Complete feature showcase
📚 Documentation
- Getting Started Guide: Installation and basic usage
- API Reference: Complete function documentation
- Examples Gallery: Comprehensive examples
- Advanced Features: Power user techniques
🧪 Dependencies
Core Dependencies
matplotlib >= 3.5.0pandas >= 1.3.0numpy >= 1.20.0scipy >= 1.7.0
Optional Dependencies
networkx >= 2.6.0(for network visualizations)plotly >= 5.0.0(for globe and interactive surface plots)
🤝 Contributing
We welcome contributions! Please see our Contributing Guide for details.
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🔗 Links
Made with ❤️ for the risk management community
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file riskplot-0.3.0.tar.gz.
File metadata
- Download URL: riskplot-0.3.0.tar.gz
- Upload date:
- Size: 4.3 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
df4a7fe306abdd71df4ef2314fc553d4637bf041226101c075f2f3a001b505d9
|
|
| MD5 |
275cb2ef56f4e47ff585ba93ed32eb08
|
|
| BLAKE2b-256 |
6f3e3b72cd1709dfdd5e22a61c0d91d2f0f905c3e30a9016472568f4dc96f78b
|
Provenance
The following attestation bundles were made for riskplot-0.3.0.tar.gz:
Publisher:
publish-to-pypi.yml on OwenDinsmore/riskplot
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
riskplot-0.3.0.tar.gz -
Subject digest:
df4a7fe306abdd71df4ef2314fc553d4637bf041226101c075f2f3a001b505d9 - Sigstore transparency entry: 567061218
- Sigstore integration time:
-
Permalink:
OwenDinsmore/riskplot@a4e114d04d9372a7a93a3cc415825fbd51f3b598 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/OwenDinsmore
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@a4e114d04d9372a7a93a3cc415825fbd51f3b598 -
Trigger Event:
release
-
Statement type:
File details
Details for the file riskplot-0.3.0-py3-none-any.whl.
File metadata
- Download URL: riskplot-0.3.0-py3-none-any.whl
- Upload date:
- Size: 35.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
af2d578eafdc602e8e1c9f20f94fcffa626978bda78f49b7ebdf56cd46f76d9d
|
|
| MD5 |
098ae27f4beebfab311691fbe561974c
|
|
| BLAKE2b-256 |
cae92fe5267fe1ba57a9075678a469a1f9aa600dc306175f2b3db86211591464
|
Provenance
The following attestation bundles were made for riskplot-0.3.0-py3-none-any.whl:
Publisher:
publish-to-pypi.yml on OwenDinsmore/riskplot
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
riskplot-0.3.0-py3-none-any.whl -
Subject digest:
af2d578eafdc602e8e1c9f20f94fcffa626978bda78f49b7ebdf56cd46f76d9d - Sigstore transparency entry: 567061223
- Sigstore integration time:
-
Permalink:
OwenDinsmore/riskplot@a4e114d04d9372a7a93a3cc415825fbd51f3b598 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/OwenDinsmore
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@a4e114d04d9372a7a93a3cc415825fbd51f3b598 -
Trigger Event:
release
-
Statement type: