On Monday, January 22, 2018 at 12:07:07 AM UTC, Simon Willerton wrote:
>
>
> On Sunday, January 21, 2018 at 7:02:24 PM UTC, William wrote:
>>
>>
>> On Sun, Jan 21, 2018 at 9:01 AM Simon Willerton <[email protected]> 
>> wrote:
>>
>>> Hi!
>>>
>>> There seems to be a bug in the plotting in the Jupyter notebook.  The 
>>> following piecewise defined function should be smooth at r=1 but the plot 
>>> is not; the first part of the plot seems to be lifted slightly.  I noticed 
>>> this in a more complicated example but this is a reasonably minimal case.
>>>
>>> r = var('r')
>>> plot(2*r - r^2, r, 0, 1) + plot(1, r, 1, 2)
>>>
>>> This bug doesn't seem to occur in CoCalc .sagews notebook but does occur 
>>> in SageMath Kernels 7.6, 8.0, 8.1 in a CoCalc Jupyter notebook and offline 
>>> on my Mac OS X Sierra in a Jupyter notebook.
>>>
>>
>> It could be an issue with svg versus png output.
>>
>>
>>>
>>> Cheers,
>>>
>>> Simon.
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "sage-support" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to [email protected].
>>> To post to this group, send email to [email protected].
>>> Visit this group at https://groups.google.com/group/sage-support.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>> -- 
>> -- William Stein
>>
>
> Indeed, that seems to be the problem.  Comparing the output from the 
> following code gives the svg as smooth but the png not smooth.
>
> p = plot(2*r- r^2, r, 0,1) + plot(1, r, 1, 2)
> p.save("plot.svg")
> p.save("plot.png")
>  
>

Following William's hint, I came up with a workaround.  The first solution 
I found at https://stackoverflow.com/a/45664729 didn't work on .sagews 
files, so combining that with https://stackoverflow.com/a/44100805, 
<https://stackoverflow.com/a/44100805> I ended up with the following.  Do 
tell me if there's a better way!


from IPython.display import SVG, display

def svg_show(pic, *args, **kwds):
    """
    Display the plot 'pic' using svg (rather than png).  If we are in 
Jupyter (ie. IPython)
    we need to do this explicitly.  Otherwise we can use the default show() 
function.
    """
    try:
        get_ipython
        pic.save('temp.svg', *args, **kwds)
        display(SVG(filename='temp.svg'))
    except:
        show(pic, *args, **kwds)

        
r = var('r')     
svg_show(plot(2*r- r^2, r, 0,1) + plot(1, r, 1, 2), ymin=0.5)

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.

Reply via email to