Add axes setters and adjustments#16
Conversation
…agement methods and properties for axis labels, visibility, and ranges
…ithmic y-axis support
…and title support
Codecov Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
…isibility controls; add get_xlim method
…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
There was a problem hiding this comment.
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.
| 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) |
| 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 |
| marker: str = "none", | ||
| markersize: float = 4.0, | ||
| label: str = ""): | ||
| label: str = "", | ||
| yscale: str = "linear"): | ||
| self._id: str = "" |
| 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 |
| 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); |
| 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))); |
| "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), |
| f"Unknown linestyle {ls!r}. Expected one of: " | ||
| "'solid', 'dashed', 'dotted', 'dashdot', " | ||
| "'solid', 'dashed', 'dotted', 'dashdot', 'step-mid' " | ||
| "or shorthands '-', '--', ':', '-.'." |
… parameters and improve error handling for axis scale settings
This pull request introduces several enhancements and new features to the
anyplotlibplotting 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:
subplots_adjustmethod to theFigureclass, 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]closemethod forFigure, which fires a"close"event on all panels and hides the widget, with subsequent calls being no-ops.drag_modetrait toFigureto enable drag handles for panel reordering in the frontend.Plotting and 1D Plot Improvements:
Axes.plotmethod now accepts ayscaleargument to support logarithmic scaling, and a conveniencesemilogymethod was added for log-y plotting. [1] [2] [3]Plot1Dreceived 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, andset_ticks_visible.Marker API Extensions and Validation:
Plot1Dnow accept atransformargument (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]removemethod toMarkerGroupfor removing marker groups from their parent and triggering a re-render.Styling and Utility Improvements:
get_color_cycle) for consistent plot coloring, and exposed it in the package API."step-mid"line styles and its alias"steps-mid"in the line style normalization utility. [1] [2]Event Handling:
"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.