![]() | 1 | initial version |
I couldn't reproduce the dvipng error, but I can explain the "TypeError: 'sage.symbolic.expression.Expression' object is not iterable" problem.
There are several different functions called "plot", including both the Sage one (which knows about and likes Sage expressions), and the plot in the matplotlib.pyplot package you import in a later cell with
from matplotlib.pyplot import figure, axes, plot, xlabel, ylabel, title, \
grid, savefig, show
This plot function doesn't know about Sage functions and expects an argument that it can loop over, which is exactly what the error message is trying to say: it's expecting something it can iterate over (like a list of points), but the sage expression you pass isn't.
The "sometimes it works, sometimes it doesn't" effect is simply measuring whether or not you executed a reset() in some cell, setting plot back to the Sage one, after you executed the above import, which is why it appears so random-- apparently your cell execution order habits are kind of random. :^)
Keeping the matplotlib functions in their own space by using the "import matplotlib.pyplot as plt"/"plt.plot" approach -- which you do in one cell -- and avoiding either "from pylab import *" or "from matplotlib.pyplot import plot" is a better idea if you're going to want to mix Sage plots and matplotlib plots.
![]() | 2 | No.2 Revision |
I couldn't reproduce the dvipng error, but I can explain the "TypeError: 'sage.symbolic.expression.Expression' object is not iterable" problem.
There are several different functions called "plot", including both the Sage one (which knows about and likes Sage expressions), and the plot in the matplotlib.pyplot package you import in a later cell with
from pylab import *
and
from matplotlib.pyplot import figure, axes, plot, xlabel, ylabel, title, \
grid, savefig, show
This plot function doesn't know about Sage functions and expects an argument that it can loop over, which is exactly what the error message is trying to say: it's expecting something it can iterate over (like a list of points), but the sage expression you pass isn't.
The "sometimes it works, sometimes it doesn't" effect is simply measuring whether or not you executed a reset() in some cell, setting plot back to the Sage one, after you executed the above import, which is why it appears so random-- apparently your cell execution order habits are kind of random. :^)
Keeping the matplotlib functions in their own space by using the "import matplotlib.pyplot as plt"/"plt.plot" approach -- which you do in one cell -- and avoiding either "from pylab import *" or "from matplotlib.pyplot import plot" is a better idea if you're going to want to mix Sage plots and matplotlib plots.
![]() | 3 | No.3 Revision |
I couldn't reproduce the dvipng error, but I can explain the "TypeError: 'sage.symbolic.expression.Expression' object is not iterable" problem.
There are several different functions called "plot", including both the Sage one (which knows about and likes Sage expressions), and the plot in the matplotlib.pyplot matplotlib package you import in a later cell cells with
from pylab import *
and
from matplotlib.pyplot import figure, axes, plot, xlabel, ylabel, title, \
grid, savefig, show
This plot function doesn't know about Sage functions and expects an argument that it can loop over, which is exactly what the error message is trying to say: it's expecting something it can iterate over (like a list of points), but the sage expression you pass isn't.
The "sometimes it works, sometimes it doesn't" effect is simply measuring whether or not you executed a reset() in some cell, setting plot back to the Sage one, after you executed the above import, which is why it appears so random-- apparently your cell execution order habits are kind of random. :^)
Keeping the matplotlib functions in their own space by using the "import matplotlib.pyplot as plt"/"plt.plot" approach -- which you do in one cell -- and avoiding either "from pylab import *" or "from matplotlib.pyplot import plot" is a better idea if you're going to want to mix Sage plots and matplotlib plots.