Ask Your Question
0

weird behavior of show command

asked 2019-09-25 10:34:10 +0100

florin gravatar image

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 flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2019-09-25 11:06:24 +0100

Emmanuel Charpentier gravatar image

updated 2019-09-25 11:12:15 +0100

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

image description

and g1prime is

image description

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

image description

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

image description

edit flag offensive delete link more

Comments

Thanks! The error on 8.8 came maybe from Spectral

florin gravatar imageflorin ( 2019-09-25 18:59:12 +0100 )edit
0

answered 2019-09-25 18:51:11 +0100

florin gravatar image

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)
edit flag offensive delete link more

Comments

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

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2019-09-25 22:05:12 +0100 )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

2 followers

Stats

Asked: 2019-09-25 10:34:10 +0100

Seen: 799 times

Last updated: Sep 25 '19