Skip to content

Add axes setters and adjustments#16

Merged
CSSFrancis merged 11 commits into
mainfrom
refactor/project-reorganization
May 23, 2026
Merged

Add axes setters and adjustments#16
CSSFrancis merged 11 commits into
mainfrom
refactor/project-reorganization

Conversation

@CSSFrancis
Copy link
Copy Markdown
Owner

This pull request introduces several enhancements and new features to the anyplotlib plotting library, focusing on improved figure and subplot management, expanded plotting and marker APIs, and better customization options. The most significant changes are grouped below by theme.

Figure and Subplot Enhancements:

  • Added subplots_adjust method to the Figure class, allowing users to set horizontal (wspace) and vertical (hspace) spacing between subplot panels; these values are now included in the figure's wire format. [1] [2] [3]
  • Introduced a close method for Figure, which fires a "close" event on all panels and hides the widget, with subsequent calls being no-ops.
  • Added a drag_mode trait to Figure to enable drag handles for panel reordering in the frontend.

Plotting and 1D Plot Improvements:

  • The Axes.plot method now accepts a yscale argument to support logarithmic scaling, and a convenience semilogy method was added for log-y plotting. [1] [2] [3]
  • Plot1D received new properties and methods for easier access and control: color, x, y, set_xlabel, set_ylabel, set_title, set_xlim, set_ylim, get_ylim, get_xbound, set_axis_off, and set_ticks_visible.

Marker API Extensions and Validation:

  • All marker-adding methods in Plot1D now accept a transform argument (default "data"), supporting coordinate transforms for marker placement; transform values are validated and included in the wire protocol. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11]
  • Added a remove method to MarkerGroup for removing marker groups from their parent and triggering a re-render.

Styling and Utility Improvements:

  • Introduced a global color cycle (get_color_cycle) for consistent plot coloring, and exposed it in the package API.
  • Added support for "step-mid" line styles and its alias "steps-mid" in the line style normalization utility. [1] [2]

Event Handling:

  • Added "close" to the set of valid event types for callbacks.

These changes collectively enhance the flexibility, usability, and extensibility of the plotting library, making it easier to create complex, interactive visualizations.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 22, 2026

Codecov Report

❌ Patch coverage is 97.30640% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.38%. Comparing base (189a4ea) to head (020fb92).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
anyplotlib/figure/_figure.py 90.00% 2 Missing ⚠️
anyplotlib/markers.py 85.71% 2 Missing ⚠️
anyplotlib/plot1d/_plot1d.py 97.05% 2 Missing ⚠️
anyplotlib/plot1d/_plotbar.py 97.40% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #16      +/-   ##
==========================================
+ Coverage   81.91%   84.38%   +2.46%     
==========================================
  Files          29       29              
  Lines        2356     2645     +289     
==========================================
+ Hits         1930     2232     +302     
+ Misses        426      413      -13     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

…or Plot1D, Plot2D, and Plot3D; enhance PlotBar with get_xlim method
…ls for Plot1D, Plot2D, and Plot3D; add y-axis scale configuration and data bounds getters
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR expands anyplotlib’s figure/panel API surface to better match familiar Matplotlib-style controls (subplot spacing, axis labels/titles/visibility, view setters), extends marker capabilities (including coordinate transforms + removal), and updates the JS renderer/wire format to support these new state fields.

Changes:

  • Added figure-level layout controls (subplots_adjust) and lifecycle handling (Figure.close() + "close" event type).
  • Extended Plot1D/Plot2D/PlotBar/Plot3D state + setters (labels, titles, axis/tick visibility, view getters/setters) and added Plot1D yscale + Axes.semilogy.
  • Expanded marker API (transform support + validation; MarkerGroup.remove) and updated JS rendering for transforms, titles, colorbar label, and view preservation behavior.

Reviewed changes

Copilot reviewed 20 out of 30 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
anyplotlib/figure/_figure.py Adds subplot spacing state into layout_json; introduces Figure.close() and subplots_adjust().
anyplotlib/figure_esm.js Frontend support for hspace/wspace, titles/labels, y-log rendering, marker transforms, and view preservation.
anyplotlib/axes/_axes.py Adds Plot1D yscale parameter plumbing and semilogy() convenience method.
anyplotlib/plot1d/_plot1d.py Adds Plot1D axis/title/ticks APIs, yscale/y_range support, and view-from-python flag behavior.
anyplotlib/plot1d/_plotbar.py Adds PlotBar label/title/ticks/view APIs and new state keys (align, y_range, etc.).
anyplotlib/plot2d/_plot2d.py Adds Plot2D label/title/colorbar label/aspect/ticks APIs and marker transform plumbing.
anyplotlib/plot2d/_plotmesh.py Adds a PlotMesh-specific __repr__.
anyplotlib/plot3d/_plot3d.py Adds Plot3D title/labels/axis visibility/view reset + view-from-python flag; repr uses vertices_count.
anyplotlib/markers.py Adds marker transform validation + wire emission, MarkerGroup.remove(), and expands known 1D marker types.
anyplotlib/callbacks.py Adds "close" to valid callback event types.
anyplotlib/_utils.py Extends linestyle normalization to include step-mid (and alias steps-mid).
anyplotlib/init.py Exposes Line1D, marker classes, and get_color_cycle() at top level.
anyplotlib/tests/test_layouts/test_gridspec.py Adds tests for subplots_adjust and initial hspace/wspace contract.
anyplotlib/tests/test_interactive/test_callbacks.py Adds tests for Figure.close() behavior and event type availability.
anyplotlib/tests/test_layouts/test_visual.py Adds visual regression tests for titles/labels/axis visibility changes.
anyplotlib/tests/test_plot1d/test_plot1d.py Adds Plot1D API/state tests (yscale, labels, ticks, getters, etc.).
anyplotlib/tests/test_plot1d/test_plotbar.py Adds PlotBar API/state tests (labels, ticks, limits, setters, etc.).
anyplotlib/tests/test_plot2d/test_plot2d_api.py Adds Plot2D API/state tests including resize/layout propagation invariants.
anyplotlib/tests/test_plot3d/test_plot3d.py Adds Plot3D API/state tests (view reset, labels, repr vertex count, etc.).
anyplotlib/tests/test_markers/test_markers.py Adds tests for MarkerGroup.remove(), 1D marker registry completeness, and wire-format checks.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread anyplotlib/figure/_figure.py Outdated
Comment on lines +154 to +170
def subplots_adjust(self, hspace: float = 0.0, wspace: float = 0.0) -> None:
"""Set the spacing between subplot panels.

Parameters
----------
hspace : float, optional
Fraction of the average row height to use as vertical gap between
panels. ``0.1`` adds a gap of 10 % of the mean row height.
Default ``0.0`` (no gap). Before ``subplots_adjust`` is called,
figures use a 4 px browser default gap.
wspace : float, optional
Fraction of the average column width to use as horizontal gap.
Default ``0.0`` (no gap). Before ``subplots_adjust`` is called,
figures use a 4 px browser default gap.
"""
self._hspace = float(hspace)
self._wspace = float(wspace)
Comment on lines +500 to +507
close_event = Event(event_type="close")
for plot in self._plots_map.values():
if hasattr(plot, "callbacks"):
plot.callbacks.fire(close_event)
try:
self.layout = {"display": "none"}
except Exception:
pass
Comment on lines 246 to 250
marker: str = "none",
markersize: float = 4.0,
label: str = ""):
label: str = "",
yscale: str = "linear"):
self._id: str = ""
Comment thread anyplotlib/plot3d/_plot3d.py Outdated
Comment on lines +202 to +210
self._state["x_label"] = label
self._push()

def set_ylabel(self, label: str) -> None:
self._state["y_label"] = label
self._push()

def set_zlabel(self, label: str) -> None:
self._state["z_label"] = label
Comment thread anyplotlib/figure_esm.js Outdated
Comment on lines +2468 to +2472
const [cx,cy]= tfm==='data' ? _offToCanvas(off) : _tc2d(off[0],off[1]!=null?off[1]:0);
const wd=ms.widths[i]!=null?ms.widths[i]:(ms.widths[0]||10);
const hd=ms.heights[i]!=null?ms.heights[i]:(ms.heights[0]||10);
const rw=Math.max(1,Math.abs(_xPx(off[0]+wd/2)-_xPx(off[0]-wd/2))/2);
const rh=Math.max(1,Math.abs(_yPx((off[1]||0)-hd/2)-_yPx((off[1]||0)+hd/2))/2);
Comment thread anyplotlib/figure_esm.js Outdated
Comment on lines +2482 to +2486
const [cx,cy]= tfm==='data' ? _offToCanvas(off) : _tc2d(off[0],off[1]!=null?off[1]:0);
const wd=ms.widths[i]!=null?ms.widths[i]:(ms.widths[0]||10);
const hd=heights[i]!=null?heights[i]:(heights[0]||10);
const rw=Math.max(1,Math.abs(_xPx(off[0]+wd/2)-_xPx(off[0]-wd/2)));
const rh=Math.max(1,Math.abs(_yPx((off[1]||0)-hd/2)-_yPx((off[1]||0)+hd/2)));
Comment on lines 185 to 190
"group_labels": list(group_labels) if group_labels is not None else [],
"group_colors": gc_list,
"bar_width": float(width),
"align": align,
"orient": orient,
"baseline": float(bottom),
Comment thread anyplotlib/_utils.py
f"Unknown linestyle {ls!r}. Expected one of: "
"'solid', 'dashed', 'dotted', 'dashdot', "
"'solid', 'dashed', 'dotted', 'dashdot', 'step-mid' "
"or shorthands '-', '--', ':', '-.'."
@CSSFrancis CSSFrancis merged commit 0097711 into main May 23, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants