Skip to content

Commit

Permalink
axis_label_from_data helper func
Browse files Browse the repository at this point in the history
  • Loading branch information
ddkohler committed Mar 27, 2024
1 parent c224400 commit fc685d2
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions WrightTools/artists/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,35 @@
# --- functions -----------------------------------------------------------------------------------


def axis_label_from_data(
data, ax=None, cax=None, which="both", channel_index=0
):
"""Apply x and/or y labels to axes.
Parameters
----------
data : WrightTools.Data
data from which to extract the label(s)
ax : Axis object (optional)
Default is current axis
autolabel : {'none', 'both', 'x', 'y'} (optional)
Label(s) to apply from data. Default is none.
channel_index : integer (optional)
Channel index. Default is 0. Only important for 2D data
"""
if ax is None:
ax = plt.gca()
if which in ["both", "x"]:
xlabel = data.axes[0].label
ax.set_xlabel(xlabel)
if which in ["both", "y"]:
if data.ndim == 1:
ylabel = data.channels[channel_index].label
elif data.ndim == 2:
ylabel = data.axes[1].label
ax.set_ylabel(ylabel)


def _title(fig, title, subtitle="", *, margin=1, fontsize=20, subfontsize=18):
"""Add a title to a figure.
Expand Down

0 comments on commit fc685d2

Please sign in to comment.