#21042 closed defect (fixed)
Contour plot of zero fails with rich representation warning
Reported by:  Paul Masson  Owned by:  

Priority:  major  Milestone:  sage9.5 
Component:  graphics  Keywords:  
Cc:  Michael Orlitzky  Merged in:  
Authors:  Michael Orlitzky  Reviewers:  Dima Pasechnik 
Report Upstream:  N/A  Work issues:  
Branch:  2d51836 (Commits, GitHub, GitLab)  Commit:  
Dependencies:  Stopgaps: 
Description (last modified by )
Attempting the contour plot
var('x y') contour_plot(0, (x,1,1), (y,1,1))
does not show a plot and fails with the error
/home/sc_serv/sage/local/lib/python2.7/sitepackages/sage/repl/rich_output/display_manager.py:590: RichReprWarning: Exception in _rich_repr_ while displaying object: zerosize array to reduction operation minimum which has no identity RichReprWarning, Graphics object consisting of 1 graphics primitive
Contour plots of nonzero values display as expected. It was reported on this ask question.
Change History (13)
comment:1 Changed 6 years ago by
Description:  modified (diff) 

comment:2 Changed 14 months ago by
Cc:  Michael Orlitzky added 

comment:3 Changed 14 months ago by
I think contour plot and implicit plot work by detecting sign changes to know where something vanishes.
So no surprise they don't work well with absolute values and squares of some quantities even though those have the same vanishing loci.
comment:5 Changed 14 months ago by
Actually... I don't think matplotlib expects levels
(our contours
) to contain only one element. We can probably fix this by using contours=[epsilon, epsilon]
instead of contours=[0]
, which does whoknowswhat under the hood.
comment:6 Changed 14 months ago by
Update: using contours=[epsilon, epsilon]
doesn't break any existing implicit plots, but how good it looks depends on epsilon
and the function you're plotting. Some functions require a lot more plot points for a given epsilon, or a smaller xrange and yrange.
I wonder if there's a cheap heuristic we could use instead of a fixed tolerance.
comment:7 Changed 12 months ago by
Authors:  → Michael Orlitzky 

Branch:  → u/mjo/ticket/21042 
Commit:  → b7e688b9a3f278d59a754948ab996873d661bece 
Status:  new → needs_review 
This heuristic is real hacky, but it can only improve things; and the important part is that we now warn the user anyway.
New commits:
49be220  Trac #21042: heuristic improvements for singlelevel contour plots.

c4c2852  Trac #21042: add warnings to implicit and contour plot docstrings.

b7e688b  Trac #21042: hide expected warnings from the sphinx plotter.

comment:8 Changed 12 months ago by
Commit:  b7e688b9a3f278d59a754948ab996873d661bece → 2d518364df619eb6211d4714e6b13ad85e651651 

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
f02bee1  Trac #21042: heuristic improvements for singlelevel contour plots.

7ca28d9  Trac #21042: add warnings to implicit and contour plot docstrings.

2d51836  Trac #21042: hide expected warnings from the sphinx plotter.

comment:9 Changed 10 months ago by
Milestone:  sage7.3 → sage9.5 

Do we want this in? The milestone was off...
comment:10 Changed 10 months ago by
Reviewers:  → Dima Pasechnik 

Status:  needs_review → positive_review 
OK, looks good
comment:11 Changed 10 months ago by
Branch:  u/mjo/ticket/21042 → 2d518364df619eb6211d4714e6b13ad85e651651 

Resolution:  → fixed 
Status:  positive_review → closed 
comment:12 followup: 13 Changed 10 months ago by
Commit:  2d518364df619eb6211d4714e6b13ad85e651651 

This has broken our linter, by using a bad comparison to False.
It's not just the zero function, something else weird is going on here. This produces the line
x=y
like you'd expect:But then this produces... nothing:
Even though it should be the same plot. Which is weird, but not as weird as being able to fix it with...
which gives you (roughly) the plot of
x=y
again.