Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

add text to hlut #348

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 28, 2023
Merged
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
57 changes: 55 additions & 2 deletions 57 fastplotlib/widgets/histogram_lut.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from typing import *
import weakref

import numpy as np

from pygfx import Group

from ..graphics import LineGraphic, ImageGraphic
from ..graphics import LineGraphic, ImageGraphic, TextGraphic
from ..graphics._base import Graphic
from ..graphics.selectors import LinearRegionSelector

Expand Down Expand Up @@ -66,19 +67,63 @@ def __init__(
self._vmin = self.image_graphic.cmap.vmin
self._vmax = self.image_graphic.cmap.vmax

vmin_str, vmax_str = self._get_vmin_vmax_str()

self._text_vmin = TextGraphic(
text=vmin_str,
size=16,
position=(0, 0),
anchor="top-left",
outline_color="black",
outline_thickness=1,
)

self._text_vmax = TextGraphic(
text=vmax_str,
size=16,
position=(0, 0),
anchor="bottom-left",
outline_color="black",
outline_thickness=1,
)

widget_wo = Group()
widget_wo.add(self.line.world_object, self.linear_region.world_object)
widget_wo.add(
self.line.world_object,
self.linear_region.world_object,
self._text_vmin.world_object,
self._text_vmax.world_object,
)

self._set_world_object(widget_wo)

self.world_object.local.scale_x *= -1

self._text_vmin.position_x = -120
self._text_vmin.position_y = self.linear_region.selection()[0]

self._text_vmax.position_x = -120
self._text_vmax.position_y = self.linear_region.selection()[1]

self.linear_region.selection.add_event_handler(
self._linear_region_handler
)

self.image_graphic.cmap.add_event_handler(self._image_cmap_handler)

def _get_vmin_vmax_str(self) -> Tuple[str, str]:
if self.vmin < 0.001 or self.vmin > 99_999:
vmin_str = f"{self.vmin:.2e}"
else:
vmin_str = f"{self.vmin:.2f}"

if self.vmax < 0.001 or self.vmax > 99_999:
vmax_str = f"{self.vmax:.2e}"
else:
vmax_str = f"{self.vmax:.2f}"

return vmin_str, vmax_str

def _add_plot_area_hook(self, plot_area):
self._plot_area = plot_area
self.linear_region._add_plot_area_hook(plot_area)
Expand Down Expand Up @@ -168,6 +213,10 @@ def vmin(self, value: float):

self._vmin = value

vmin_str, vmax_str = self._get_vmin_vmax_str()
self._text_vmin.position_y = self.linear_region.selection()[0]
self._text_vmin.text = vmin_str

@property
def vmax(self) -> float:
return self._vmax
Expand All @@ -185,6 +234,10 @@ def vmax(self, value: float):

self._vmax = value

vmin_str, vmax_str = self._get_vmin_vmax_str()
self._text_vmax.position_y = self.linear_region.selection()[1]
self._text_vmax.text = vmax_str

def set_data(self, data, reset_vmin_vmax: bool = True):
hist, edges, hist_scaled, edges_flanked = self._calculate_histogram(data)

Expand Down
2 changes: 1 addition & 1 deletion 2 fastplotlib/widgets/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ def __init__(
)

subplot.docks["right"].add_graphic(hlut)
subplot.docks["right"].size = 50
subplot.docks["right"].size = 80
subplot.docks["right"].auto_scale(maintain_aspect=False)
subplot.docks["right"].controller.enabled = False

Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.