Skip to content
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

Issue with plot labels #218

Merged
merged 4 commits into from
Aug 16, 2022
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
16 changes: 13 additions & 3 deletions anesthetic/samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ def plot_1d(self, axes, *args, **kwargs):

for x, ax in axes.iteritems():
if x in self and kwargs['kind'] is not None:
self[x].plot(ax=ax, *args, **kwargs)
xlabel = self.tex[x] if x in self.tex else x
self[x].plot(ax=ax, xlabel=xlabel,
*args, **kwargs)
ax.set_xlabel(xlabel)
else:
ax.plot([], [])

Expand Down Expand Up @@ -241,10 +244,17 @@ def plot_2d(self, axes, *args, **kwargs):
lkwargs = local_kwargs.get(pos, {})
lkwargs['kind'] = kind.get(pos, None)
if x in self and y in self and lkwargs['kind'] is not None:
xlabel = self.tex[x] if x in self.tex else x
ylabel = self.tex[y] if y in self.tex else y
if x == y:
self[x].plot(ax=ax.twin, *args, **lkwargs)
self[x].plot(ax=ax.twin, xlabel=xlabel,
*args, **lkwargs)
ax.set_xlabel(xlabel)
else:
self.plot(x, y, ax=ax, *args, **lkwargs)
self.plot(x, y, ax=ax, xlabel=xlabel,
ylabel=ylabel, *args, **lkwargs)
ax.set_xlabel(xlabel)
ax.set_ylabel(ylabel)
else:
if x == y:
ax.twin.plot([], [])
Expand Down
12 changes: 12 additions & 0 deletions tests/test_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -942,3 +942,15 @@ def test_samples_dot_plot():
pass

plt.close("all")


def test_samples_plot_labels():
samples = NestedSamples(root='./tests/example_data/pc')
columns = ['x0', 'x1', 'x2', 'x3', 'x4']
fig, axes = samples.plot_2d(columns)

for col, ax in zip(columns, axes.loc[:, 'x0']):
assert samples.tex[col] == ax.get_ylabel()

for col, ax in zip(columns, axes.loc['x4', :]):
assert samples.tex[col] == ax.get_xlabel()