Ticket #11500 (new defect)

Opened 2 years ago

Last modified 10 months ago

Problem with accumulating 3D plots over a parameter

Reported by: travis Owned by: jason, was
Priority: minor Milestone: sage-5.10
Component: graphics Keywords: plot3d
Cc: kcrisman Work issues:
Report Upstream: N/A Reviewers:
Authors: Merged in:
Dependencies: Stopgaps:

Description (last modified by travis) (diff)

When creating several layers that interpolate between two surfaces, only one layer is output when accumulating the layers via a loop. No problem if the layers are explicitly coded.

In the looped version, it appears that the plot3d commands are only executed at show() time and therefore only use the final value of the loop parameter. All of the layers are created on top of each other at that final parameter value.

This works:

P += plot3d(lambda x,y: H(x,y,tiers[2]/10),(x,-1,1),(y,-1,1),opacity=0.2)

P += plot3d(lambda x,y: H(x,y,tiers[5]/10),(x,-1,1),(y,-1,1),opacity=0.2)

P += plot3d(lambda x,y: H(x,y,tiers[8]/10),(x,-1,1),(y,-1,1),opacity=0.2)

show(P)

This does not:

for r in ratios:

P += plot3d(lambda x,y: H(x,y,r),(x,-1,1),(y,-1,1),opacity=0.2) # layer

show(P)

Example worksheet is attached.

Attachments

Plot3d bug.sws Download (402.8 KB) - added by travis 2 years ago.

Change History

Changed 2 years ago by travis

comment:1 Changed 2 years ago by travis

  • Cc kcrisman added; krisman removed

comment:2 Changed 2 years ago by kcrisman

John, try to copy a minimal example with code so that people don't have to upload it to look at this ticket :) Thanks for getting the spelling right :)

comment:3 Changed 2 years ago by jason

I don't think there is any guarantee that the function is actually executed when the plot3d command is called, is there? You are exposing this because the lambda function does not create a new scope. If instead you use a def function instead of a lambda function, things should work fine.

I agree that it is confusing. I'm trying to decide if it is "wrong".

I've published this worksheet here:  http://sagenb.org/home/pub/2823/

comment:4 Changed 2 years ago by jason

Okay, after thinking about it and discussing this with KDC, I think the current behavior is wrong. I agree with kcrisman that the plot3d command should "freeze" the variables by creating a closure (or a fast_callable object) when it stores the function.

comment:5 Changed 2 years ago by travis

  • Description modified (diff)

comment:6 Changed 10 months ago by kcrisman

  • Owner changed from jason, mpatel, was to jason, was
  • Component changed from notebook to graphics
Note: See TracTickets for help on using tickets.