Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nvaytet committed Aug 7, 2023
1 parent fb5bec2 commit f269631
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/plopp/plotting/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ def plot(
'vmax': vmax,
'autoscale': autoscale,
'figsize': figsize,
'legend': legend,
**kwargs,
}

Expand All @@ -128,6 +127,7 @@ def plot(
*[Node(da) for da in data_arrays],
errorbars=errorbars,
mask_color=mask_color,
legend=legend,
**common_args,
)
elif ndim == 2:
Expand Down
21 changes: 21 additions & 0 deletions tests/plotting/plot_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,3 +376,24 @@ def test_plot_pandas_dataframe():
assert p.canvas.units['x'] == 'dimensionless'
assert p.canvas.units['y'] == 'dimensionless'
assert len(p._view.artists) == 4


def test_hide_legend():
da1 = data_array(ndim=1)
da2 = da1 * 3.3
p = pp.plot({'a': da1, 'b': da2}, legend=False)
leg = p.ax.get_legend()
assert leg is None


def test_legend_location():
da1 = data_array(ndim=1)
da2 = da1 * 3.3
data = {'a': da1, 'b': da2}
leg1 = pp.plot(data, legend=(0.5, 0.5)).ax.get_legend().get_window_extent().bounds
leg2 = pp.plot(data, legend=(0.9, 0.5)).ax.get_legend().get_window_extent().bounds
leg3 = pp.plot(data, legend=(0.5, 0.9)).ax.get_legend().get_window_extent().bounds
assert leg2[0] > leg1[0]
assert leg2[1] == leg1[1]
assert leg3[1] > leg1[1]
assert leg3[0] == leg1[0]

0 comments on commit f269631

Please sign in to comment.