Skip to content

Commit 4b49eb0

Browse files
authored
Merge branch 'main' into fix/animation-noise
2 parents 51020d2 + f607880 commit 4b49eb0

File tree

12 files changed

+1953
-127
lines changed

12 files changed

+1953
-127
lines changed

.github/workflows/build-ultraplot.yml

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ jobs:
5454
compare-baseline:
5555
name: Compare baseline Python ${{ inputs.python-version }} with MPL ${{ inputs.matplotlib-version }}
5656
runs-on: ubuntu-latest
57+
env:
58+
IS_PR: ${{ github.event_name == 'pull_request' }}
5759
defaults:
5860
run:
5961
shell: bash -el {0}
@@ -75,22 +77,25 @@ jobs:
7577
- name: Cache Baseline Figures
7678
id: cache-baseline
7779
uses: actions/cache@v4
80+
if: ${{ env.IS_PR }}
7881
with:
7982
path: ./ultraplot/tests/baseline # The directory to cache
80-
# Key is based on OS, Python/Matplotlib versions, and the PR number
81-
key: ${{ runner.os }}-baseline-pr-${{ github.event.pull_request.number }}-${{ inputs.python-version }}-${{ inputs.matplotlib-version }}
83+
# Key is based on OS, Python/Matplotlib versions, and the base commit SHA
84+
key: ${{ runner.os }}-baseline-base-${{ github.event.pull_request.base.sha }}-${{ inputs.python-version }}-${{ inputs.matplotlib-version }}
8285
restore-keys: |
83-
${{ runner.os }}-baseline-pr-${{ github.event.pull_request.number }}-${{ inputs.python-version }}-${{ inputs.matplotlib-version }}-
86+
${{ runner.os }}-baseline-base-${{ github.event.pull_request.base.sha }}-${{ inputs.python-version }}-${{ inputs.matplotlib-version }}-
8487
8588
# Conditional Baseline Generation (Only runs on cache miss)
8689
- name: Generate baseline from main
8790
# Skip this step if the cache was found (cache-hit is true)
88-
if: steps.cache-baseline.outputs.cache-hit != 'true'
91+
if: steps.cache-baseline.outputs.cache-hit != 'true' || !env.IS_PR
8992
run: |
9093
mkdir -p ultraplot/tests/baseline
91-
# Checkout the base branch (e.g., 'main') to generate the official baseline
92-
git fetch origin ${{ github.event.pull_request.base.sha }}
93-
git checkout ${{ github.event.pull_request.base.sha }}
94+
# Checkout the base commit for PRs; otherwise regenerate from current ref
95+
if [ -n "${{ github.event.pull_request.base.sha }}" ]; then
96+
git fetch origin ${{ github.event.pull_request.base.sha }}
97+
git checkout ${{ github.event.pull_request.base.sha }}
98+
fi
9499
95100
# Install the Ultraplot version from the base branch's code
96101
pip install --no-build-isolation --no-deps .
@@ -103,7 +108,9 @@ jobs:
103108
ultraplot/tests
104109
105110
# Return to the PR branch for the rest of the job
106-
git checkout ${{ github.sha }}
111+
if [ -n "${{ github.event.pull_request.base.sha }}" ]; then
112+
git checkout ${{ github.sha }}
113+
fi
107114
108115
# Image Comparison (Uses cached or newly generated baseline)
109116
- name: Image Comparison Ultraplot

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ docs/_build
2222
docs/_static/ultraplotrc
2323
docs/_static/rctable.rst
2424
docs/_static/*
25+
docs/gallery/
26+
docs/sg_execution_times.rst
27+
docs/whats_new.rst
2528

2629
# Development subfolders
2730
dev
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"""
2+
Layered Sankey diagram
3+
======================
4+
5+
An example of UltraPlot's layered Sankey renderer for publication-ready
6+
flow diagrams.
7+
8+
Why UltraPlot here?
9+
-------------------
10+
``sankey`` in layered mode handles node ordering, flow styling, and
11+
label placement without manual geometry.
12+
13+
Key function: :py:meth:`ultraplot.axes.PlotAxes.sankey`.
14+
15+
See also
16+
--------
17+
* :doc:`2D plot types </2dplots>`
18+
"""
19+
20+
import ultraplot as uplt
21+
22+
nodes = ["Budget", "Operations", "R&D", "Marketing", "Support", "Infra"]
23+
flows = [
24+
("Budget", "Operations", 5.0, "Ops"),
25+
("Budget", "R&D", 3.0, "R&D"),
26+
("Budget", "Marketing", 2.0, "Mkt"),
27+
("Operations", "Support", 1.5, "Support"),
28+
("Operations", "Infra", 2.0, "Infra"),
29+
]
30+
31+
fig, ax = uplt.subplots(refwidth=3.6)
32+
ax.sankey(
33+
nodes=nodes,
34+
flows=flows,
35+
style="budget",
36+
flow_labels=True,
37+
value_format="{:.1f}",
38+
node_label_box=True,
39+
flow_label_pos=0.5,
40+
)
41+
ax.format(title="Budget allocation")
42+
fig.show()

ultraplot/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@
4848
"Colormap": ("constructor", "Colormap"),
4949
"Cycle": ("constructor", "Cycle"),
5050
"Norm": ("constructor", "Norm"),
51+
"Locator": ("constructor", "Locator"),
52+
"Scale": ("constructor", "Scale"),
53+
"Formatter": ("constructor", "Formatter"),
5154
}
5255

5356

ultraplot/axes/base.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2889,10 +2889,10 @@ def _update_outer_abc_loc(self, loc):
28892889
# Get the size of tick labels if they exist
28902890
has_labels = True if axis.get_ticklabels() else False
28912891
# Estimate label size; note it uses the raw text representation which can be misleading due to the latex processing
2892-
if has_labels:
2892+
if has_labels and axis.get_ticklabels():
28932893
_offset = max(
28942894
[
2895-
len(l.get_text()) + l.get_fontsize()
2895+
len(l.get_text()) * l.get_fontsize() * 0.6
28962896
for l in axis.get_ticklabels()
28972897
]
28982898
)
@@ -3429,6 +3429,8 @@ def format(
34293429
return
34303430
if rc_mode == 1: # avoid resetting
34313431
return
3432+
if self._inset_parent is not None or self._panel_parent is not None:
3433+
return
34323434
self.figure.format(rc_kw=rc_kw, rc_mode=rc_mode, skip_axes=True, **params)
34333435

34343436
def draw(self, renderer=None, *args, **kwargs):

0 commit comments

Comments
 (0)