Skip to content
Draft
Show file tree
Hide file tree
Changes from 51 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
69ad6ea
soft deprecate plot_colorbar
ddkohler Mar 22, 2024
0b3f566
Merge branch 'master' into plan-plot_colorbar-deprecation
ddkohler Mar 22, 2024
daa1e46
Update CHANGELOG.md
ddkohler Mar 22, 2024
5c9eaa0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 22, 2024
8122951
fix 2 warnings
ddkohler Mar 22, 2024
7ab3ab7
test build
ddkohler Mar 23, 2024
1509e85
Update fringes_transform.py
ddkohler Mar 23, 2024
8242466
test node20
ddkohler Mar 23, 2024
1834767
Update fringes_transform.py
ddkohler Mar 23, 2024
13386fd
try more for sphinx
ddkohler Mar 23, 2024
06e32b7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 23, 2024
31fa0bd
Update split.py
ddkohler Mar 23, 2024
fdf358c
re-implement module reset (#1175)
ddkohler Mar 24, 2024
ddf2db8
new example for norms, cbar
ddkohler Mar 31, 2024
c75a0d6
Merge branch 'master' into plan-plot_colorbar-deprecation
ddkohler Mar 31, 2024
39c36bf
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 31, 2024
1622cd9
abandon using datasets as module
ddkohler Mar 31, 2024
5cd0cf5
try new load method
ddkohler Apr 1, 2024
0be6b2e
datasets us SimpleNamespace
ddkohler Apr 1, 2024
6dc130e
Merge branch 'master' into plan-plot_colorbar-deprecation
ddkohler Apr 1, 2024
813228a
Update norms.py
ddkohler Apr 1, 2024
274f789
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 1, 2024
35fc3a2
codeql
ddkohler Apr 1, 2024
6b4832d
Merge branch 'master' into plan-plot_colorbar-deprecation
ddkohler Apr 29, 2024
fa536ed
axis_label_from_data, deprecation warnings
ddkohler May 3, 2024
537c93f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 3, 2024
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).

## Changed
- artists now gets turbo colormap straight from matplotlib
- deprecating `artists.plot_colorbar`: instead use matplotlib's `colorbar` implementations directly
- artists.interact2D now returns a `types.SimpleNamespace` object (rather than a tuple)

## [3.5.2]
Expand Down
3 changes: 2 additions & 1 deletion WrightTools/artists/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ def _parse_plot_args(self, *args, **kwargs):
data=data, channel_index=channel_index, dynamic_range=dynamic_range, **kwargs
)
if plot_type == "contourf":
if "levels" not in kwargs.keys():
if ("levels" not in kwargs.keys()) and ("norm" not in kwargs):
# because of _parse_limits, we ensur we always have vmin and vmax to use
kwargs["levels"] = np.linspace(kwargs["vmin"], kwargs["vmax"], 256)
elif plot_type == "contour":
if "levels" not in kwargs.keys():
Expand Down
48 changes: 46 additions & 2 deletions WrightTools/artists/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.patheffects as PathEffects

from matplotlib.colors import Normalize, CenteredNorm, TwoSlopeNorm
from mpl_toolkits.axes_grid1 import make_axes_locatable

import imageio.v3 as iio
Expand All @@ -33,6 +35,7 @@
"create_figure",
"diagonal_line",
"get_scaled_bounds",
"norm_from_channel",
"pcolor_helper",
"plot_colorbar",
"plot_margins",
Expand All @@ -43,6 +46,7 @@
"set_fig_labels",
"subplots_adjust",
"stitch_to_animation",
"ticks_from_norm",
]


Expand Down Expand Up @@ -653,6 +657,11 @@ def plot_colorbar(
matplotlib.colorbar.ColorbarBase object
The created colorbar.
"""
warnings.warn(
"`plot_colorbar` is planned for deprecation. "
+ "Use `matplotlib.pyplot.colorbar` instead.",
wt_exceptions.VisibleDeprecationWarning,
)
# parse cax
if cax is None:
cax = plt.gca()
Expand Down Expand Up @@ -1043,8 +1052,11 @@ def set_fig_labels(


def subplots_adjust(fig=None, inches=1):
"""Enforce margins for generated figure, starting at subplots.
.. note::
"""
Enforce margins for generated figure, starting at subplots.

Note
----
You probably should be using wt.artists.create_figure instead.

Parameters
Expand Down Expand Up @@ -1116,3 +1128,35 @@ def stitch_to_animation(paths, outpath=None, *, duration=0.5, palettesize=256, v
interval = np.round(t.interval, 2)
print("gif generated in {0} seconds - saved at {1}".format(interval, outpath))
return outpath


def norm_from_channel(channel, dynamic_range=False):
if channel.signed:
if dynamic_range:
norm = TwoSlopeNorm(vcenter=channel.null, vmin=channel.min(), vmax=channel.max())
else:
norm = CenteredNorm(vcenter=channel.null, halfrange=channel.mag())
if norm.halfrange == 0:
norm.halfrange = 1
else:
norm = Normalize(vmin=channel.null, vmax=np.nanmax(channel[:]))
if norm.vmax == norm.vmin:
norm.vmax += 1
return norm


def ticks_from_norm(norm, n=11) -> np.array:
if type(norm) == CenteredNorm:
vmin = norm.vcenter - norm.halfrange
vmax = norm.vcenter + norm.halfrange
elif type(norm) == Normalize:
vmin = norm.vmin
vmax = norm.vmax
elif type(norm) == TwoSlopeNorm:
mag = max(norm.vcenter - norm.vmin, norm.vmax - norm.vcenter)
in_range = lambda x: x >= norm.vmin and x <= norm.vmax
temp = [x for x in filter(in_range, np.linspace(-mag, mag, n))]
temp[0] = norm.vmin
temp[-1] = norm.vmax
return np.array(temp)
return np.linspace(vmin, vmax, n)
4 changes: 3 additions & 1 deletion WrightTools/artists/_interact.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,9 @@ def interact2D(
# colorbar
ticks = current_state.norm.ticks
ticklabels = gen_ticklabels(ticks, channel.signed)
colorbar = plot_colorbar(cax, cmap=cmap, label=channel.natural_name, ticks=ticks)
colorbar = fig.colorbar(
mappable=obj2D, cax=cax, cmap=cmap, label=channel.natural_name, ticks=ticks
)
colorbar.set_ticklabels(ticklabels)
fig.canvas.draw_idle()

Expand Down
Loading