Ask Your Question

Error using matplotlib gallery examples in SageMath verbatim

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

Cheng gravatar image

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

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)

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

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

tmonteil gravatar image

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


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:

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


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

Seen: 214 times

Last updated: May 08 '21