Latex Transition Problem

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

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.

( 2019-02-19 14:20:45 -0600 )edit

Sort by » oldest newest most voted

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}

more

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

( 2019-02-19 14:05:57 -0600 )edit