Ask Your Question

# weird behavior of show command

Hi The code

f(x,y)=x^3-x^2 + y^2;print f
g1 = contour_plot(f(x,y),(x,-2,2),(y,-2,2),contours=20,fill=False,cmap='spectral')
show(g1)


produces a plot with a hyperbolic point. On my computer, repeating this

show(g1)


yields a different plot

The purpose was to show this together with gradient field

f(x,y)=(x+2)^2/(y^2+ (x-1/2)^2) ;print f
g1 = contour_plot(f(x,y),(x,-2,6),(y,-2,4),contours=[1/10,1/2,4/5,1,2,3],cmap='spectral',fill=False)
df=f.gradient()
show(df)
g2 = plot_vector_field(df,(x,-2,2),(y,-2,2))


This doesn't work, since the first plot is incorrect show(g1+g2)

edit retag close merge delete

## 2 answers

Sort by ยป oldest newest most voted

Since you didn't show the first and the second attempt to get g1, we can only guess.

var("x, y")
f(x,y)=x^3-x^2+y^2
# BTW, the correct name is "Spectral", not "spectral"...
g1 = contour_plot(f(x,y),(x,-2,2),(y,-2,2),
contours=20,fill=False,cmap='Spectral')
g1prime = contour_plot(f(x,y),(x,-2,6),(y,-2,4),
contours=[1/10,1/2,4/5,1,2,3],cmap='Spectral',fill=False)


for me, g1 is

and g1prime is

They are obviously different, since you changed:

• the ranges, and
• the contours specification.

Now, adding

g2=plot_vector_field(f.gradient(), (x, -2, 2), (y, -2, 2))


to the first graph (same range specification) gives me

which does not look that unreasonable... Compare with a 3D view of the function in the same ranges:

more

## Comments

Thanks! The error on 8.8 came maybe from Spectral

( 2019-09-25 11:59:12 -0600 )edit

I reinstalled the latest Windows version 8.8. repeating now a second time the show(g1) yields error!

RuntimeError                              Traceback (most recent call last)
<ipython-input-20-2dbcc4c9974d> in <module>()
----> 1 show(g1)

/opt/sagemath-8.8/local/lib/python2.7/site-packages/sage/repl/rich_output/pretty_print.pyc in show(*args, **kwds)
256         args[0].show()
257         return
--> 258     pretty_print(*args, **kwds)

/opt/sagemath-8.8/local/lib/python2.7/site-packages/sage/repl/rich_output/pretty_print.pyc in pretty_print(*args, **kwds)
227             pass
228         elif len(args) == 1:
--> 229             dm.display_immediately(*args, **kwds)
230         else:
231             SequencePrettyPrinter(*args, **kwds).pretty_print()

/opt/sagemath-8.8/local/lib/python2.7/site-packages/sage/repl/rich_output/display_manager.pyc in display_immediately(self, obj, **rich_repr_kwds)
833             1/2
834         """
--> 835         plain_text, rich_output = self._rich_output_formatter(obj, rich_repr_kwds)
836         self._backend.display_immediately(plain_text, rich_output)
837

/opt/sagemath-8.8/local/lib/python2.7/site-packages/sage/repl/rich_output/display_manager.pyc in _rich_output_formatter(self, obj, rich_repr_kwds)
633         if rich_output is None:
634             rich_output = self._preferred_text_formatter(
--> 635                 obj, plain_text=plain_text, **rich_repr_kwds)
636         # promote output container types to backend-specific containers
637         plain_text = self._promote_output(plain_text)

/opt/sagemath-8.8/local/lib/python2.7/site-packages/sage/repl/rich_output/display_manager.pyc in _preferred_text_formatter(self, obj, plain_text, **kwds)
535             return out
536         if want == 'latex' and OutputLatex in supported:
--> 537             out = self._backend.latex_formatter(obj, **kwds)
538             if type(out) is not OutputLatex:
539                 raise OutputTypeException('backend returned wrong output type, require Latex')

/opt/sagemath-8.8/local/lib/python2.7/site-packages/sage/repl/rich_output/backend_base.pyc in latex_formatter(self, obj, **kwds)
482             mathjax = MathJax().eval(obj, mode='plain', combine_all=True)
483         else:
--> 484             mathjax = MathJax().eval(obj, mode='plain', combine_all=False)
485         from sage.repl.rich_output.output_basic import OutputLatex
486         return OutputLatex(str(mathjax))

/opt/sagemath-8.8/local/lib/python2.7/site-packages/sage/misc/latex.pyc in eval(self, x, globals, locals, mode, combine_all)
1951         """
1952         # Get a regular LaTeX representation of x
-> 1953         x = latex(x, combine_all=combine_all)
1954
1955         # The following block, hopefully, can be removed in some future MathJax.

/opt/sagemath-8.8/local/lib/python2.7/site-packages/sage/misc/latex.pyc in __call__(self, x, combine_all)
923         """
924         if has_latex_attr(x):
--> 925             return LatexExpr(x._latex_())
926         try:
927             f = latex_table[type(x)]

/opt/sagemath-8.8/local/lib/python2.7/site-packages/sage/plot/graphics.py in _latex_(self, **kwds)
3240         """
3241         tmpfilename = tmp_filename(ext='.pgf')
-> 3242         self.save(filename=tmpfilename, **kwds)
3243         with open(tmpfilename, "r") as tmpfile:
3244                 latex_list = tmpfile.readlines()

/opt/sagemath-8.8/local/lib/python2.7/site-packages/sage/misc/decorators.pyc in wrapper(*args, **kwds)
410             kwds[self.name + "options"] = suboptions
411
--> 412             return func(*args, **kwds)
413
414         # Add the options specified by @options to the signature of the wrapped

/opt/sagemath-8.8/local/lib/python2.7/site-packages/sage/plot/graphics.py in save(self, filename, **kwds)
3165             rc_backup = (rcParams['ps.useafm'], rcParams['pdf.use14corefonts'],
3166                          rcParams['text.usetex']) # save the rcParams
-> 3167             figure = self.matplotlib(**options)
3168             # You can output in PNG, PS, EPS, PDF, PGF, or SVG format, depending
3169             # on the file extension.

/opt/sagemath-8.8/local/lib/python2.7/site-packages/sage/plot/graphics.py in matplotlib(self, filename, xmin, xmax, ymin, ymax, figsize, figure, sub, axes, axes_labels, axes_labels_size, fontsize, frame, verify, aspect_ratio, gridlines, gridlinesstyle, vgridlinesstyle, hgridlinesstyle, show_legend, legend_options, axes_pad, ticks_integer, tick_formatter, ticks, title, title_pos, base, scale, stylesheet, typeset)
2616                     pass
2617             g.set_options(opts)
-> 2618             g._render_on_subplot(subplot)
2619             if hasattr(g, '_bbox_extra_artists'):
2620                 self._bbox_extra_artists.extend(g._bbox_extra_artists)

/opt/sagemath-8.8/local/lib/python2.7/site-packages/sage/plot/contour_plot.py in _render_on_subplot(self, subplot)
159         contours = options['contours']
160         if 'cmap' in options:
--> 161             cmap = get_cmap(options['cmap'])
162         elif fill or contours is None:
163             cmap = get_cmap('gray')

/opt/sagemath-8.8/local/lib/python2.7/site-packages/sage/plot/colors.py in get_cmap(cmap)
1418     elif isinstance(cmap, six.string_types):
1419         if not cmap in cm.datad:
-> 1420             raise RuntimeError("Color map %s not known (type import matplotlib.cm; matplotlib.cm.datad.keys() for valid names)" % cmap)
1421         return cm.__dict__[cmap]
1422

RuntimeError: Color map spectral not known (type import matplotlib.cm; matplotlib.cm.datad.keys() for valid names)

more

## Comments

Again, it's "Spectral", not "spectral" (capital "s", please...).

( 2019-09-25 15:05:12 -0600 )edit

## Your Answer

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

Add Answer

## Stats

Asked: 2019-09-25 03:34:10 -0600

Seen: 118 times

Last updated: Sep 25 '19