Ask Your Question

Using matplotlib inside Sage

asked 2016-08-22 13:27:30 -0500

Federico gravatar image

I have difficulties in using matplotlib commands inside Sage.

I took a demo from matplotlib's website:

Simple demo of a horizontal bar chart.
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.pyplot as plt

# Example data
people = ('Tom', 'Dick', 'Harry', 'Slim', 'Jim')
y_pos = np.arange(len(people))
performance = 3 + 10 * np.random.rand(len(people))
error = np.random.rand(len(people))

plt.barh(y_pos, performance, xerr=error, align='center', alpha=0.4)
plt.yticks(y_pos, people)
plt.title('How fast do you want to go today?')

If I run it as python code (e.g. %run inside ipython) it works and shows a bar chart on the screen; if I run it inside sage or sage -python, then I see no result. I presume that Sage does some wrapping of matplotlib's output that interacts with the plotting?

How can I properly use matplotlib inside Sage code?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2016-08-23 14:17:59 -0500

ndomes gravatar image



instead of
edit flag offensive delete link more


And if you want to see the image file:

from PIL import Image
image ='mychart.png')
paulmasson gravatar imagepaulmasson ( 2016-08-23 15:22:41 -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


Asked: 2016-08-22 13:27:30 -0500

Seen: 58 times

Last updated: Aug 23 '16