Skip to content

Commit

Permalink
option to plot lines just within measured point boundaries (#60)
Browse files Browse the repository at this point in the history
Added the ``draw_in_bounds`` option to the curve plotting so that curves never are plotted outside the data range. Addresses [this issue](#59).
  • Loading branch information
jbloom authored Apr 11, 2024
1 parent c6b0c4b commit c619220
Show file tree
Hide file tree
Showing 6 changed files with 365 additions and 271 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@ All notable changes to this project will be documented in this file.

The format is based on `Keep a Changelog <https://keepachangelog.com>`_.

2.1.0
-----

Added
+++++
- Added the ``draw_in_bounds`` option to the curve plotting so that curves never are plotted outside the data range. Addresses [this issue](https://github.com/jbloomlab/neutcurve/issues/59).

2.0.1
-----

Fixed
+++++
- Don't throw an uninterprtable error if ``CurveFits.fitParams`` called with no curves, instead just return empty data frame.
- Don't throw an uninterpretable error if ``CurveFits.fitParams`` called with no curves, instead just return empty data frame.

2.0.0
-----
Expand Down
2 changes: 1 addition & 1 deletion neutcurve/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

__author__ = "Jesse Bloom"
__email__ = "[email protected]"
__version__ = "2.0.1"
__version__ = "2.1.0"
__url__ = "https://github.com/jbloomlab/neutcurve"

from neutcurve.curvefits import CurveFits # noqa: F401
Expand Down
4 changes: 4 additions & 0 deletions neutcurve/curvefits.py
Original file line number Diff line number Diff line change
Expand Up @@ -1243,6 +1243,7 @@ def plotGrid(
sharex=True,
sharey=True,
vlines=None,
draw_in_bounds=False,
):
"""Plot arbitrary grid of curves.
Expand Down Expand Up @@ -1318,6 +1319,8 @@ def plotGrid(
Values are lists of dicts with a key 'x' giving the x-location
of the vertical line, and optionally keys 'linewidth',
'color', and 'linestyle'.
`draw_in_bounds` (bool)
Same meaning as for meth:`neutcurve.hillcurve.HillCurve.plot`.
Returns:
The 2-tuple `(fig, axes)` of matplotlib figure and 2D axes array.
Expand Down Expand Up @@ -1468,6 +1471,7 @@ def plotGrid(
xlabel=ixlabel,
ylabel=iylabel,
yticklocs=yticklocs,
draw_in_bounds=draw_in_bounds,
**kwargs,
)
label = curvedict["label"]
Expand Down
14 changes: 11 additions & 3 deletions neutcurve/hillcurve.py
Original file line number Diff line number Diff line change
Expand Up @@ -1203,6 +1203,7 @@ def plot(
linewidth=1,
linestyle="-",
yticklocs=None,
draw_in_bounds=False,
):
"""Plot the neutralization curve.
Expand All @@ -1229,12 +1230,16 @@ def plot(
Line style.
`yticklocs` (`None` or list)
Exact locations to place yticks; `None` means auto-locate.
`draw_in_bounds` (bool)
By default, the plotted curve extends a bit outside the actual
data points on both sides. If this is set to `True`, then the
plotted curve stops at the bounds of the data points.
Returns:
The 2-tuple `(fig, ax)` giving the matplotlib figure and axis.
"""
data = self.dataframe(concentrations)
data = self.dataframe(concentrations, extend=0 if draw_in_bounds else 0.1)

if ax is None:
fig, ax = plt.subplots()
Expand Down Expand Up @@ -1282,7 +1287,7 @@ def plot(

return fig, ax

def dataframe(self, concentrations="auto"):
def dataframe(self, concentrations="auto", extend=0.1):
"""Get data frame with curve data for plotting.
Useful if you want to get both the points and the fit
Expand All @@ -1294,6 +1299,9 @@ def dataframe(self, concentrations="auto"):
If 'auto' the automatically computed from data
range using :func:`concentrationRange`. If
'measured' then only include measured values.
`extend` (float)
The value passed to :func:`concentrationRange` if `concentrations`
is 'auto'.
Returns:
A pandas DataFrame with the following columns:
Expand All @@ -1306,7 +1314,7 @@ def dataframe(self, concentrations="auto"):
"""
if concentrations == "auto":
concentrations = concentrationRange(self.cs[0], self.cs[-1])
concentrations = concentrationRange(self.cs[0], self.cs[-1], extend=extend)
elif concentrations == "measured":
concentrations = []
concentrations = numpy.concatenate([self.cs, concentrations])
Expand Down
Loading

0 comments on commit c619220

Please sign in to comment.