Ask Your Question
1

Latex Transition Problem

asked 2019-02-19 19:49:01 +0100

EnlightenedFunk gravatar image

updated 2019-02-22 18:49:33 +0100

FrédéricC gravatar image

I have been getting this error UnboundLocalError: local variable 'xmin' referenced before assignment and I have been wondering why the error is present. And how I could fix it to get the LaTex for it.

Sage: from sage.graphs.graph_plot import GraphPlot
Sage: options = {
....:   'vertex_size': 200,
....:   'vertex_labels': True,
....:   'layout': None,
....:   'edge_style': 'solid',
....:   'edge_color': 'black',
....:   'edge_colors': None,
....:   'edge_labels': False,
....:   'iterations': 50,
....:   'tree_orientation': 'down',
....:   'heights': None,
....:   'graph_border': False,
....:   'talk': False,
....:   'color_by_label': False,
....:   'partition': None,
....:   'dist': .075,
....:   'max_dist': 1.5,
....:   'loop_size': .075,
....:   'edge_labels_background': 'transparent'}

Sage:xmin = -10 
     xmax = 10
     f = plot((x^2-2)/(x+2), (x,xmin, xmax), ymin = -20, ymax = 20)
     pt1 = point((-2,2), rgbcolor='blue', pointsize=40)
     z = Graph((f+pt1).show(xmin= xmin, xmax= xmax, ymin=-20, ymax=20))
     GP = GraphPlot(z, options)
Sage:z.set_latex_options(
....: graphic_size=(5,5),
....: vertex_size=0.2,
....: edge_thickness=0.04,
....: edge_color='green',
....: vertex_color='green',
....: vertex_label_color='red'
....: )
Sage: latex(z)
edit retag flag offensive close merge delete

Comments

GraphPlotis for plotting the mathematical "graph" object – see https://en.wikipedia.org/wiki/Graph_t..., for example. It is not for plotting graphs of functions. I don't believe that there is a way in Sage to get LaTeX output for producing the graph of a function like (x^2-2)/(x+2). The LaTeX package TikZ/PGF can do that, but that's independent of Sage.

John Palmieri gravatar imageJohn Palmieri ( 2019-02-19 21:20:45 +0100 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2019-02-19 21:00:55 +0100

tmonteil gravatar image

updated 2019-02-23 12:15:21 +0100

Your construction does not really makes sense : (f+pt1).show(xmin= xmin, xmax= xmax, ymin=-20, ymax=20) does not return anything, since the show method does just plot something, but does not return any object, hence the construction of z corresponds to the empty graph, and you can check:

sage: z == Graph(None)
True

So, what do you want to achieve ?

EDIT

Only the following 4 lines are useful:

xmin = -10 
xmax = 10
f = plot((x^2-2)/(x+2), (x,xmin, xmax), ymin = -20, ymax = 20)
pt1 = point((-2,2), rgbcolor='blue', pointsize=40)

Everything else is about discrete graphs (those with vertices and edges), not with functionnal graphs, nor graphics.

It turns out that matplotlib, which Sage uses to render such plots is able to export to latex (using pgf package), and Sage has a an interface to it. You can do:

latex(f+pt1)

and copy-paste the long text you get into your latex file. To let the code work, you have to add the pgf package in your latex file:

\usepackage{pgf}
edit flag offensive delete link more

Comments

I want to latex out the figure that is done in the graph?

EnlightenedFunk gravatar imageEnlightenedFunk ( 2019-02-19 21:05:57 +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

1 follower

Stats

Asked: 2019-02-19 19:49:01 +0100

Seen: 698 times

Last updated: Feb 23 '19