Ask Your Question

Fast plots - How do I do those?

asked 2015-08-20 17:06:40 -0500

Peter Luschny gravatar image

I have no experience with Sage plots so I think I make something wrong. With Maple


takes less than 1 second and it looks perfect.

With Sage (executed at SMC)

f = lambda x,n: (exp(i*x*(1-n))*(1+(exp(exp(i*x))-1)/(exp(2*exp(i*x))+1))).real()
bat = plot(f(x,0), (0,2*pi), color=Color(0,0,0), ymin=-1.6, ymax=1.6)
for n in sxrange(1,20,1):
    bat += plot(f(x,n), (0,2*pi), rgbcolor=(n/2,n/5,n/3), ymin=-1.6, ymax=1.6)

takes longer than the lifespan of Methuselah. How can I speed things up?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2015-08-21 13:55:36 -0500

fidbc gravatar image

A possibility would be to use matplotlib+numpy. For example:

import numpy as np
import matplotlib.pyplot as plt

def get_f( n ):
    def func(t):
        return np.exp(i*t*(1-n))*(1+(np.exp(np.exp(i*t))-1)/(np.exp(2*np.exp(i*t))+1))
    return func

def mat_plot():
    t = np.arange(0.,2*np.pi,0.01)
    for i in range(20):
        func = get_f(i)
        ft = func(t)

Takes only 0.5s at SMC (and 234ms on my laptop). Sample output:

image description

edit flag offensive delete link more



Excellent, thanks! I call this plot Bernoulli's batman. If you want to know why you can go here:

Peter Luschny gravatar imagePeter Luschny ( 2015-08-21 14:27:28 -0500 )edit

@Peter Luschny Nice! Are you planning on translating the source on the appendix to Sagemath?

fidbc gravatar imagefidbc ( 2015-08-22 16:21:26 -0500 )edit

Yes, I will add also a Sage version and add your graphic script, if you allow. The page is still under construction and more things might come.

Peter Luschny gravatar imagePeter Luschny ( 2015-08-24 12:52:55 -0500 )edit

As long as it preserves the same CC license I'm fine. I'll try to tweak the code a bit more.

fidbc gravatar imagefidbc ( 2015-08-25 18:52:15 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2015-08-20 17:06:40 -0500

Seen: 243 times

Last updated: Aug 21 '15