Skip to content

Commit

Permalink
Add option to directly set contour zorder (#23)
Browse files Browse the repository at this point in the history
* Add option to explicitly set zorder of contours
  • Loading branch information
ThomasGesseyJones authored Feb 3, 2025
1 parent 4763205 commit fc82884
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 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.4.2
:Version: 2.4.3
:Homepage: https://github.com/handley-lab/fgivenx
:Documentation: http://fgivenx.readthedocs.io/

Expand Down
16 changes: 14 additions & 2 deletions fgivenx/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ def plot(x, y, z, ax=None, **kwargs):
easier when you have dense contours.
(Default: False)
zorder: float, optional
z-order of plotted components. (Default: matplotlib default)
filled_zorder: float, optional
z-order of filled contours. Overrides zorder. (Default: matplotlib default)
lines_zorder: float, optional
z-order of contour lines. Overrides zorder. (Default: matplotlib default)
Returns
-------
cbar: color bar
Expand Down Expand Up @@ -81,6 +90,9 @@ def plot(x, y, z, ax=None, **kwargs):

lines = kwargs.pop('lines', True)

filled_zorder = kwargs.pop('filled_zorder', kwargs.get('zorder', None))
lines_zorder = kwargs.pop('lines_zorder', kwargs.pop('zorder', None))

if kwargs:
raise TypeError('Unexpected **kwargs: %r' % kwargs)

Expand All @@ -94,7 +106,7 @@ def plot(x, y, z, ax=None, **kwargs):

# Plot the filled contours onto the axis ax
cbar = ax.contourf(x, y, z, cmap=colors, levels=contour_color_levels,
alpha=alpha)
alpha=alpha, zorder=filled_zorder)

# Rasterize contours (the rest of the figure stays in vector format)
if rasterize_contours:
Expand All @@ -108,7 +120,7 @@ def plot(x, y, z, ax=None, **kwargs):
# Plot some sigma-based contour lines
if lines:
ax.contour(x, y, z, colors='k', linewidths=linewidths,
levels=contour_line_levels)
levels=contour_line_levels, zorder=lines_zorder)

# Return the contours for use as a colourbar later
return cbar
Expand Down

0 comments on commit fc82884

Please sign in to comment.