Python Integration
GoFigr’s Python package provides seamless figure capture for all major visualization libraries.
Supported Libraries
Section titled “Supported Libraries”| Library | Auto-capture | Manual capture |
|---|---|---|
| Matplotlib | ✅ | ✅ |
| Seaborn | ✅ | ✅ |
| Plotly | ✅ | ✅ |
Jupyter Notebooks
Section titled “Jupyter Notebooks”Auto-Configured Setup (Simplest)
Section titled “Auto-Configured Setup (Simplest)”Just load the extension:
%load_ext gofigrThat’s it! GoFigr will:
- Automatically use your default workspace from
gfconfig - Create or use an analysis named after your notebook
- Enable auto-publish (automatically captures all figures)
All figures you create will be automatically published:
%load_ext gofigr
import matplotlib.pyplot as pltimport pandas as pdimport numpy as np
# Create a simple plotdf = pd.DataFrame({'x': np.random.randn(100), 'y': np.random.randn(100)})plt.scatter(df['x'], df['y'])plt.title('Random Scatter Plot')
# This figure is automatically published!Custom Configuration
Section titled “Custom Configuration”For more control, use the configure() function:
%load_ext gofigr
from gofigr.jupyter import configure, FindByName, ApiId, NotebookName
configure( workspace=FindByName("Primary Workspace", create=False), analysis=FindByName("My Analysis", create=True), auto_publish=True, default_metadata={ 'requested_by': "Alyssa", 'study': 'Pivotal Trial 1' })Configuration Options
Section titled “Configuration Options”| Option | Description |
|---|---|
workspace |
FindByName("Name"), ApiId("uuid"), or None (use default) |
analysis |
FindByName("Name", create=True), NotebookName(), or ApiId("uuid") |
auto_publish |
If True, all figures are automatically published |
default_metadata |
Dictionary of metadata to store with each revision |
api_key |
Override API key (if not using default from gfconfig) |
Manual Publishing
Section titled “Manual Publishing”If you set auto_publish=False, manually publish figures:
%load_ext gofigr
from gofigr.jupyter import configure, FindByName, publish
configure(auto_publish=False, analysis=FindByName("My Analysis", create=True))
import matplotlib.pyplot as plt
plt.plot([1, 2, 3, 4], [1, 4, 9, 16])plt.title('Manual Publish Example')
# Manually publishpublish(fig=plt.gcf(), target=FindByName("My Figure", create=True))Standalone Scripts
Section titled “Standalone Scripts”Use the Publisher class for scripts outside Jupyter:
import matplotlib.pyplot as pltfrom gofigr.publisher import Publisher
# Initialize the publisherpub = Publisher(workspace="My Workspace", analysis="Script Analysis")
# Create a figureplt.plot([1, 2, 3], [1, 4, 9])plt.title('Quadratic Function')
# Publish the figurepub.publish(plt.gcf())Complete Script Example
Section titled “Complete Script Example”import seaborn as snsimport matplotlib.pyplot as pltimport plotly.express as pxfrom gofigr.publisher import Publisher
# Setup GoFigr Publisherpub = Publisher(workspace="My Workspace", analysis="Penguin Analysis")
# Load datapenguins = sns.load_dataset("penguins")
# Create and publish a Seaborn plotsns.scatterplot(data=penguins, x="flipper_length_mm", y="bill_length_mm", hue="species")plt.title("Penguin Measurements (Seaborn)")pub.publish(plt.gcf())
# Create and publish a Plotly plotfig = px.scatter(penguins, x="flipper_length_mm", y="bill_length_mm", color="species", title="Penguin Measurements (Plotly)")pub.publish(fig)Asset Tracking
Section titled “Asset Tracking”GoFigr can automatically track data files used in your analyses.
Using Tracked Data Reading
Section titled “Using Tracked Data Reading”Use gf.read_csv() instead of pd.read_csv() to automatically track data:
%load_ext gofigr
# gf is automatically available after loading the extensiondf = gf.read_csv('data/penguins.csv')
# The DataFrame is now linked to the tracked assetprint(df.attrs.get('_gofigr_revision')) # Shows the asset revision IDSupported Reading Methods
Section titled “Supported Reading Methods”| Method | File Type |
|---|---|
gf.read_csv() |
CSV files |
gf.read_excel() |
Excel files |
gf.read_json() |
JSON files |
gf.read_parquet() |
Parquet files |
gf.read_feather() |
Feather files |
gf.read_pickle() |
Pickle files |
All methods accept the same parameters as their pandas counterparts.
Manual Asset Syncing
Section titled “Manual Asset Syncing”# Sync a file without reading itgf.sync.sync('data/penguins.csv')
# Or use as a context managerwith gf.sync.open('data/raw_data.txt', 'r') as f: content = f.read()