Repository navigation
Conversation
SymPy's limit does not return for sin(x)/x + Heaviside(x - 1) at x = 0, so plot_piecewise hung on this expression. Rewrite sign, Heaviside, floor, ceiling and frac as Piecewise first, and look for the holes of a Piecewise in each piece, inside the set where the piece applies.
Author
|
Hi @Davide-sd, a gentle reminder about this pull request. The CI workflows are waiting for approval, since this is my first contribution here. The first commit (the |
Owner
|
Hello @inayatku , thanks for this PR. Sorry for the late reply, busy weeks for me. I just launched the CI run... |
The plotting range is split at the vertical asymptotes that are inside a piece, so that 1/(x - 1) is no longer drawn with a vertical line at x = 1. Vertical asymptotes are the singular points where a one-sided limit is infinite. If there are vertical asymptotes in the plotting range and ylim is not given, the y-limits are taken from the values that are not close to them, so that the two branches near a pole do not look like one vertical line.
Author
|
I added a commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
plot_piecewisedraws filled and empty dots at the ends of the pieces of aPiecewiseexpression. Functions with jumps that are not written asPiecewisewere drawn with vertical lines and no dots. Removable discontinuities were not shown.This PR:
sign,Heaviside,floor,ceilingandfracasPiecewiseover the plotting range before the pieces are processed.floor,ceilingandfracare rewritten only when their argument is linear in the plotting variable and the range covers at most 100 integer steps;(x**2 - 1)/(x - 1)atx = 1,sin(x)/xatx = 0, and the two ends ofAbs(x)/xatx = 0;x = 1for1/(x - 1): the plotting range is split there. Ifylimis not given, the y-limits are taken from the values that are not close to the vertical asymptotes, so that the two branches near a pole do not look like one vertical line;offset *= egave a negative offset, so the piece was evaluated outside its interval, and the empty dot could be NaN. For example,Piecewise((sqrt(1/2 - x), x < 1/2), (1, True))lost its empty dot atx = 1/2.Before and after, with
plot_piecewise(expr, (x, a, b)):Before:
After:
Tests: five new tests in
tests/plot_functions/test_functions_2d.py. With the change,tests/graphics,tests/plot_functions,tests/test_series.py,tests/test_utils.pyandtests/backends/test_matplotlib.pygive 563 passed, 206 skipped and 4 xfailed (558 passed before, the same skips and xfails). The existing doctest examples ofplot_piecewisegive the same output, except the last one, where1/xis now split atx = 0.Related SymPy issues: sympy/sympy#17738 and sympy/sympy#26328.