Feature implementation from commits 53355ca..9120862 by yashuatla · Pull Request #3 · yashuatla/matplotlib · GitHub
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/api/bezier_api.rst
4 changes: 4 additions & 0 deletions doc/api/next_api_changes/deprecations/30070-OG.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
``BezierSegment.point_at_t``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

... is deprecated. Instead, it is possible to call the BezierSegment with an argument.
10 changes: 10 additions & 0 deletions doc/api/next_api_changes/removals/30004-DS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
``apply_theta_transforms`` option in ``PolarTransform``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Applying theta transforms in `~matplotlib.projections.polar.PolarTransform` and
`~matplotlib.projections.polar.InvertedPolarTransform` has been removed, and
the ``apply_theta_transforms`` keyword argument removed from both classes.

If you need to retain the behaviour where theta values
are transformed, chain the ``PolarTransform`` with a `~matplotlib.transforms.Affine2D`
transform that performs the theta shift and/or sign shift.
4 changes: 0 additions & 4 deletions doc/api/next_api_changes/removals/xxxxxx-DS.rst

This file was deleted.

4 changes: 4 additions & 0 deletions doc/devel/document.rst
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,10 @@ understandable by humans. If the possible types are too complex use a
simplification for the type description and explain the type more
precisely in the text.

We do not use formal type annotation syntax for type descriptions in
docstrings; e.g. we use ``list of str`` rather than ``list[str]``; we
use ``int or str`` rather than ``int | str`` or ``Union[int, str]``.

Generally, the `numpydoc docstring guide`_ conventions apply. The following
rules expand on them where the numpydoc conventions are not specific.

Expand Down
2 changes: 1 addition & 1 deletion galleries/examples/axisartist/demo_axis_direction.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def setup_axes(fig, rect):
grid_helper = GridHelperCurveLinear(
(
Affine2D().scale(np.pi/180., 1.) +
PolarAxes.PolarTransform(apply_theta_transforms=False)
PolarAxes.PolarTransform()
),
extreme_finder=angle_helper.ExtremeFinderCycle(
20, 20,
Expand Down
3 changes: 1 addition & 2 deletions galleries/examples/axisartist/demo_curvelinear_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ def curvelinear_test2(fig):

# PolarAxes.PolarTransform takes radian. However, we want our coordinate
# system in degree
tr = Affine2D().scale(np.pi/180, 1) + PolarAxes.PolarTransform(
apply_theta_transforms=False)
tr = Affine2D().scale(np.pi/180, 1) + PolarAxes.PolarTransform()
# Polar projection, which involves cycle, and also has limits in
# its coordinates, needs a special method to find the extremes
# (min, max of the coordinate within the view).
Expand Down
5 changes: 2 additions & 3 deletions galleries/examples/axisartist/demo_floating_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def setup_axes2(fig, rect):
With custom locator and formatter.
Note that the extreme values are swapped.
"""
tr = PolarAxes.PolarTransform(apply_theta_transforms=False)
tr = PolarAxes.PolarTransform()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🐛 Correctness Issue

Removed critical transformation parameter.

Removing apply_theta_transforms=False will change how angles are processed, breaking the expected visualization output.

Current Code (Diff):

-     tr = PolarAxes.PolarTransform()
+     tr = PolarAxes.PolarTransform(apply_theta_transforms=False)
📝 Committable suggestion

‼️ IMPORTANT
Trust, but verify! 🕵️ Please review this suggestion with the care of a code archaeologist - check that it perfectly replaces the highlighted code, preserves all lines, maintains proper indentation, and won't break anything in production. Your future self will thank you! 🚀

Suggested change
tr = PolarAxes.PolarTransform()
tr = PolarAxes.PolarTransform(apply_theta_transforms=False)

🔄 Dependencies Affected

galleries/examples/axisartist/demo_floating_axes.py

Function: setup_axes2

Issue: The visualization will render incorrectly due to changed angle transformation behavior

Suggestion: No change needed in the dependency if the parameter is restored in the original file



pi = np.pi
angle_ticks = [(0, r"$0$"),
Expand Down Expand Up @@ -99,8 +99,7 @@ def setup_axes3(fig, rect):
# scale degree to radians
tr_scale = Affine2D().scale(np.pi/180., 1.)

tr = tr_rotate + tr_scale + PolarAxes.PolarTransform(
apply_theta_transforms=False)
tr = tr_rotate + tr_scale + PolarAxes.PolarTransform()

grid_locator1 = angle_helper.LocatorHMS(4)
tick_formatter1 = angle_helper.FormatterHMS()
Expand Down
3 changes: 1 addition & 2 deletions galleries/examples/axisartist/demo_floating_axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
def curvelinear_test2(fig):
"""Polar projection, but in a rectangular box."""
# see demo_curvelinear_grid.py for details
tr = Affine2D().scale(np.pi / 180., 1.) + PolarAxes.PolarTransform(
apply_theta_transforms=False)
tr = Affine2D().scale(np.pi / 180., 1.) + PolarAxes.PolarTransform()

extreme_finder = angle_helper.ExtremeFinderCycle(20,
20,
Expand Down
3 changes: 1 addition & 2 deletions galleries/examples/axisartist/simple_axis_pad.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ def setup_axes(fig, rect):
"""Polar projection, but in a rectangular box."""

# see demo_curvelinear_grid.py for details
tr = Affine2D().scale(np.pi/180., 1.) + PolarAxes.PolarTransform(
apply_theta_transforms=False)
tr = Affine2D().scale(np.pi/180., 1.) + PolarAxes.PolarTransform()

extreme_finder = angle_helper.ExtremeFinderCycle(20, 20,
lon_cycle=360,
Expand Down
48 changes: 15 additions & 33 deletions galleries/examples/images_contours_and_fields/multi_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@
value *x* in the image).

If we want one colorbar to be representative for multiple images, we have
to explicitly ensure consistent data coloring by using the same data
normalization for all the images. We ensure this by explicitly creating a
``norm`` object that we pass to all the image plotting methods.
to explicitly ensure consistent data coloring by using the same
data-to-color pipeline for all the images. We ensure this by explicitly
creating a `matplotlib.colorizer.Colorizer` object that we pass to all
the image plotting methods.
"""

import matplotlib.pyplot as plt
import numpy as np

from matplotlib import colors
import matplotlib.colorizer as mcolorizer
import matplotlib.colors as mcolors

np.random.seed(19680801)

Expand All @@ -31,12 +33,13 @@
fig, axs = plt.subplots(2, 2)
fig.suptitle('Multiple images')

# create a single norm to be shared across all images
norm = colors.Normalize(vmin=np.min(datasets), vmax=np.max(datasets))
# create a colorizer with a predefined norm to be shared across all images
norm = mcolors.Normalize(vmin=np.min(datasets), vmax=np.max(datasets))
colorizer = mcolorizer.Colorizer(norm=norm)

images = []
for ax, data in zip(axs.flat, datasets):
images.append(ax.imshow(data, norm=norm))
images.append(ax.imshow(data, colorizer=colorizer))

fig.colorbar(images[0], ax=axs, orientation='horizontal', fraction=.1)

Expand All @@ -45,30 +48,10 @@
# %%
# The colors are now kept consistent across all images when changing the
# scaling, e.g. through zooming in the colorbar or via the "edit axis,
# curves and images parameters" GUI of the Qt backend. This is sufficient
# for most practical use cases.
#
# Advanced: Additionally sync the colormap
# ----------------------------------------
#
# Sharing a common norm object guarantees synchronized scaling because scale
# changes modify the norm object in-place and thus propagate to all images
# that use this norm. This approach does not help with synchronizing colormaps
# because changing the colormap of an image (e.g. through the "edit axis,
# curves and images parameters" GUI of the Qt backend) results in the image
# referencing the new colormap object. Thus, the other images are not updated.
#
# To update the other images, sync the
# colormaps using the following code::
#
# def sync_cmaps(changed_image):
# for im in images:
# if changed_image.get_cmap() != im.get_cmap():
# im.set_cmap(changed_image.get_cmap())
#
# for im in images:
# im.callbacks.connect('changed', sync_cmaps)
#
# curves and images parameters" GUI of the Qt backend. Additionally,
# if the colormap of the colorizer is changed, (e.g. through the "edit
# axis, curves and images parameters" GUI of the Qt backend) this change
# propagates to the other plots and the colorbar.
#
# .. admonition:: References
#
Expand All @@ -77,6 +60,5 @@
#
# - `matplotlib.axes.Axes.imshow` / `matplotlib.pyplot.imshow`
# - `matplotlib.figure.Figure.colorbar` / `matplotlib.pyplot.colorbar`
# - `matplotlib.colorizer.Colorizer`
# - `matplotlib.colors.Normalize`
# - `matplotlib.cm.ScalarMappable.set_cmap`
# - `matplotlib.cbook.CallbackRegistry.connect`
38 changes: 26 additions & 12 deletions galleries/users_explain/colors/colorbar_only.py
Loading