Ask Your Question
1

Error using matplotlib gallery examples in SageMath verbatim

asked 2021-05-08 09:08:26 +0100

Cheng gravatar image

updated 2021-05-08 11:20:10 +0100

slelievre gravatar image

I am interested in the double pendulum problem from the matplotlib gallery.

After pasting the source code into the Jupyter notebook, this error occurred:

TypeError Traceback (most recent call last)

<ipython-input-1-fcbcf0dba74b> in <module>
     72 time_template = 'time = %.1fs'
     73 time_text = ax.text(RealNumber('0.05'), RealNumber('0.9'), '', transform=ax.transAxes)
---> 74 history_x, history_y = deque(maxlen=history_len), deque(maxlen=history_len)
     75 
     76 

TypeError: an integer is required

Does anyone know how to fix this?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2021-05-08 11:01:32 +0100

tmonteil gravatar image

This is because Sage uses a preparser so that when you type:

a=2

Sage preparser replaces it with

a = Integer(2)

before sending it to Pytohn, so that a is a genuine integer, not a bare int.

The deque function does not support the Sage Integers, so you have to provide it a Python int. You can either do:

  • tell the preparser not to touch the 500 in the definition of history_len :

    sage: history_len = 500r
    
  • convert the Sage Integer back to a Python int:

    history_len = int(500)
    
  • deactivate the preparser on the whole worksheet, by adding the following cell at the beginning of the worksheet:

    preparser(False)
    
edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 2021-05-08 08:42:20 +0100

Seen: 269 times

Last updated: May 08 '21