Skip to content

Commit 9bbb7cc

Browse files
Raina Thomascopybara-github
authored andcommitted
Expose setting yticks and yticklabels for plotting.
PiperOrigin-RevId: 864773912 Change-Id: Id46d5193a92efa60009e3efe44afdcd89e2693b0
1 parent bbb465e commit 9bbb7cc

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

‎src/alphagenome/visualization/plot_components.py‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,8 @@ def __init__(
419419
ylabel_horizontal: bool = True,
420420
shared_y_scale: bool = False,
421421
global_ylims: tuple[float, float] | None = None,
422+
yticks: Sequence[float] | None = None,
423+
yticklabels: Sequence[str] | None = None,
422424
alpha: float = 0.8,
423425
order_tdata_by_mean: bool = True,
424426
max_num_tracks: int = 50,
@@ -437,6 +439,12 @@ def __init__(
437439
shared_y_scale: Whether to use the same y-axis scale for all tracks. This
438440
is inferred from the min/max data values across all tracks.
439441
global_ylims: Optional global y-axis limits (min and max).
442+
yticks: Optional set y-axis tick values manually. If not provided, the
443+
tick values will be automatically determined. If provided, the length of
444+
yticks must match the length of yticklabels.
445+
yticklabels: Optional set y-axis tick labels manually. If not provided,
446+
the tick values will be automatically determined. If provided, the
447+
length of yticklabels must match the length of yticks.
440448
alpha: The transparency of the tracks.
441449
order_tdata_by_mean: Whether to order the tracks by their mean value (in
442450
descending order).
@@ -461,12 +469,24 @@ def __init__(
461469
self._ylabel_horizontal = ylabel_horizontal
462470
self._shared_y_scale = shared_y_scale
463471
self._global_ylims = global_ylims
472+
self._yticks = yticks
473+
self._yticklabels = yticklabels
464474
self._alpha = alpha
465475
self._order_tdata_by_mean = order_tdata_by_mean
466476
self._kwargs = kwargs
467477
self._first_tdata = list(tdata.values())[0]
468478
self._legend_loc = legend_loc
469479

480+
if (
481+
self._yticks is not None
482+
and self._yticklabels is not None
483+
and len(self._yticks) != len(self._yticklabels)
484+
):
485+
raise ValueError(
486+
'If passing yticks and yticklabels, the length of yticks must match'
487+
' the length of yticklabels.'
488+
)
489+
470490
if len(set(data.values.shape for data in tdata.values())) != 1:
471491
raise ValueError('Shapes of track data values must be the same.')
472492

@@ -592,6 +612,11 @@ def _make_ordered_dict_by_mean(tdata):
592612
if axis_index == 0 and self._legend_loc is not None:
593613
ax.legend(self._tdata_ordered.keys(), loc=self._legend_loc)
594614

615+
if self._yticks is not None:
616+
ax.set_yticks(self._yticks)
617+
if self._yticklabels is not None:
618+
ax.set_yticklabels(self._yticklabels)
619+
595620
if self._ylabel_template:
596621
_set_ylabel(ax, self._get_ylabel(axis_index), self._ylabel_horizontal)
597622

0 commit comments

Comments
 (0)