Skip to content

Commit

Permalink
Fixed unintuitive fineness behaviour (#15)
Browse files Browse the repository at this point in the history
Fixed the unintuitive fineness behaviour (issue #13) by removing the last contour level, such that contour levels for e.g. fineness=0.5 and contours [1,2] are now [0.5,1,1.5,2,2] instead of [0.5,1,1.5,2,2,2.5].
  • Loading branch information
Stefan Heimersheim authored Dec 13, 2021
1 parent e49b034 commit c6be8f9
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ fgivenx: Functional Posterior Plotter
=====================================
:fgivenx: Functional Posterior Plotter
:Author: Will Handley
:Version: 2.3.0
:Version: 2.4.0
:Homepage: https://github.com/williamjameshandley/fgivenx
:Documentation: http://fgivenx.readthedocs.io/

Expand Down
9 changes: 5 additions & 4 deletions fgivenx/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ def plot(x, y, z, ax=None, **kwargs):
Thickness of contour lines. (Default: 0.3)
contour_color_levels: List[float], optional
Contour color levels.
(Default: `numpy.arange(0, contour_line_levels[-1] + 1, fineness)`)
Contour color levels. (Default:
`numpy.arange(0, contour_line_levels[-1] + fineness / 2, fineness)`)
fineness: float, optional
Spacing of contour color levels. (Default: 0.1)
Spacing of contour color levels. (Default: 0.5)
lines: bool, optional
(Default: True)
Expand All @@ -69,7 +69,8 @@ def plot(x, y, z, ax=None, **kwargs):
contour_line_levels = kwargs.pop('contour_line_levels', [1, 2, 3])

fineness = kwargs.pop('fineness', 0.5)
default_color_levels = numpy.arange(0, contour_line_levels[-1] + 1,
default_color_levels = numpy.arange(0,
contour_line_levels[-1] + fineness / 2,
fineness)
contour_color_levels = kwargs.pop('contour_color_levels',
default_color_levels)
Expand Down
8 changes: 8 additions & 0 deletions fgivenx/test/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ def test_plot_transparent():
cbar = plot(x, y, z, ax, alpha=0.7)
assert type(cbar) is matplotlib.contour.QuadContourSet

def test_plot_fineness():
x, y, z = gen_plot_data()

fig, ax = plt.subplots()
cbar = plot(x, y, z, ax, fineness=0.1, contour_line_levels=[1,2,3,4])
assert type(cbar) is matplotlib.contour.QuadContourSet
assert len(cbar.levels) == 41


def test_plot_wrong_argument():
x, y, z = gen_plot_data()
Expand Down
Binary file modified planck.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified plot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c6be8f9

Please sign in to comment.