1 | initial version |
Yes, latex+sagetex+tikz is really powerful, but the answer to your question is: it can't be used as you're attempting with the Altermundus packages. The basic problem, I think, is that package designers don't design their package to plot using Sage so attempts to force it as the engine can result in problems like you encountered. I eventually learned of that problem (just like you) as I experimented with using Sage as the plotting engine. My experiments in plotting with sagetex show it works best with pgfplots. Uploading pictures to this site seems to be prevented since the site was hacked so I've put together a post on using sagetex to plot with scaled axes (using pgfplots and the picture from the Altermundus manual). It's here. And this is the template.
\documentclass{standalone}
\usepackage{sagetex}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{pgfplots}
\pagestyle{empty}
\begin{document}
\begin{sagesilent}
t = var('t')
LowerX = -6
UpperX = 3
LowerY = -2
UpperY = 6
step = .01
Scale = 1.2
xscale=1
yscale=.5
x_coords = [t for t in srange(LowerX,UpperX,step)]
y_coords = [((-t^2+t+2)*exp(t)).n(digits=6) for t in srange(LowerX,UpperX,step)]
output = r""
output += r"\begin{tikzpicture}[scale=%f]"%(Scale)
output += r"\begin{axis}["
output += r" grid = both,"
output += r"minor tick num=4,"
output += r"every major grid/.style={Red!30, opacity=1.0},"
output += r"every minor grid/.style={ForestGreen!30, opacity=1.0},"
output += r"height= %f\textwidth,"%(yscale)
output += r"width = %f\textwidth,"%(xscale)
output += r"thick,"
output += r"black,"
output += r"scale=%f,"%(Scale)
output += r"axis lines=center,"
output += r"domain=%f:%f"%(LowerX,UpperX)
output += r"samples=500,"
output += r"line join=bevel,"
output += r"xmin=%f,xmax=%f,ymin= %f,ymax=%f]"%(LowerX,UpperX,LowerY, UpperY)
output += r"\addplot[NavyBlue,unbounded coords=jump] coordinates {"
for i in range(0,len(x_coords)-1):
if (y_coords[i])<LowerY or (y_coords[i])>UpperY:
output += r"(%f , inf) "%(x_coords[i])
else:
output += r"(%f , %f) "%(x_coords[i],y_coords[i])
output += r"};"
u = var('u')
f = (-u^2+u+2)*exp(u)
m(u) = diff(f,u,1)
tan_line(u)=m(0)*u+2
x1_coords = [u for u in srange(-2.6,1.8,.01)]
y1_coords = [tan_line(u) for u in srange(-2.6,1.8,.01)]
output += r"\addplot[Peach,unbounded coords=jump] coordinates {"
for i in range(0,len(x1_coords)-1):
if (y_coords[i])<LowerY or (y1_coords[i])>UpperY:
output += r"(%f , inf) "%(x1_coords[i])
else:
output += r"(%f , %f) "%(x1_coords[i],y1_coords[i])
output += r"};"
output += r"\end{axis}"
output += r"\end{tikzpicture}"
\end{sagesilent}
\sagestr{output}
\end{document}
2 | No.2 Revision |
Yes, latex+sagetex+tikz is really powerful, but the answer to your question is: it can't be used as you're attempting with the Altermundus packages. The basic problem, I think, is that package designers don't design their package to plot using Sage so attempts to force it as the engine can result in problems like you encountered. I eventually learned of that problem (just like you) as I experimented with using Sage as the plotting engine. My experiments in plotting with sagetex show it works best with pgfplots. Uploading pictures to this site seems to be prevented since the site was hacked so I've put together a post on using sagetex to plot with scaled axes (using pgfplots and the picture from the Altermundus manual). It's here. And this is the template.
\documentclass{standalone}
\usepackage{sagetex}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{pgfplots}
\pagestyle{empty}
\begin{document}
\begin{sagesilent}
t = var('t')
LowerX = -6
UpperX = 3
LowerY = -2
UpperY = 6
step = .01
Scale = 1.2
xscale=1
yscale=.5
x_coords = [t for t in srange(LowerX,UpperX,step)]
y_coords = [((-t^2+t+2)*exp(t)).n(digits=6) for t in srange(LowerX,UpperX,step)]
output = r""
output += r"\begin{tikzpicture}[scale=%f]"%(Scale)
output += r"\begin{axis}["
output += r" grid = both,"
output += r"minor tick num=4,"
output += r"every major grid/.style={Red!30, opacity=1.0},"
output += r"every minor grid/.style={ForestGreen!30, opacity=1.0},"
output += r"height= %f\textwidth,"%(yscale)
output += r"width = %f\textwidth,"%(xscale)
output += r"thick,"
output += r"black,"
output += r"scale=%f,"%(Scale)
output += r"axis lines=center,"
output += r"domain=%f:%f"%(LowerX,UpperX)
output += r"samples=500,"
output += r"xlabel={$\omega,c^{-1}$},ylabel={$M_c,HM$},"
output += r"every axis x label/.style={"
output += r"at={(ticklabel* cs:1.03)},anchor=west,},"
output += r"every axis y label/.style={"
output += r"at={(ticklabel* cs:1.05)},anchor=south,},"
output += r"line join=bevel,"
output += r"xmin=%f,xmax=%f,ymin= %f,ymax=%f]"%(LowerX,UpperX,LowerY, UpperY)
output += r"\addplot[NavyBlue,unbounded coords=jump] coordinates {"
for i in range(0,len(x_coords)-1):
if (y_coords[i])<LowerY or (y_coords[i])>UpperY:
output += r"(%f , inf) "%(x_coords[i])
else:
output += r"(%f , %f) "%(x_coords[i],y_coords[i])
output += r"};"
u = var('u')
f = (-u^2+u+2)*exp(u)
m(u) = diff(f,u,1)
tan_line(u)=m(0)*u+2
x1_coords = [u for u in srange(-2.6,1.8,.01)]
y1_coords = [tan_line(u) for u in srange(-2.6,1.8,.01)]
output += r"\addplot[Peach,unbounded coords=jump] coordinates {"
for i in range(0,len(x1_coords)-1):
if (y_coords[i])<LowerY or (y1_coords[i])>UpperY:
output += r"(%f , inf) "%(x1_coords[i])
else:
output += r"(%f , %f) "%(x1_coords[i],y1_coords[i])
output += r"};"
output += r"\end{axis}"
output += r"\end{tikzpicture}"
\end{sagesilent}
\sagestr{output}
\end{document}
EDIT: I've added code to address axis labels and position. I noted the same problems you did. It's just trial and error looking for a method that works. One thing to mention that can cause problems. Sometimes code doesn't work because a previous attempt to run has corrupted things. You can see that if you click on the Build tab and force LaTeX, Sage, LaTeX. In that case, deleting all the non tex files for the project and running can get it to work. The part of the code cs:1.03 is putting the label 103 percent of the x-axis. Try changing that number to .7 or .99 to see how the label moves. I've run into issues trying to format the labels as you did.
3 | No.3 Revision |
Yes, latex+sagetex+tikz is really powerful, but the answer to your question is: it can't be used as you're attempting with the Altermundus packages. The basic problem, I think, is that package designers don't design their package to plot using Sage so attempts to force it as the engine can result in problems like you encountered. I eventually learned of that problem (just like you) as I experimented with using Sage as the plotting engine. My experiments in plotting with sagetex show it works best with pgfplots. Uploading pictures to this site seems to be prevented since the site was hacked so I've put together a post on using sagetex to plot with scaled axes (using pgfplots and the picture from the Altermundus manual). It's here. And this is the template.
\documentclass{standalone}
\usepackage{sagetex}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{pgfplots}
\pagestyle{empty}
\begin{document}
\begin{sagesilent}
t = var('t')
LowerX = -6
UpperX = 3
LowerY = -2
UpperY = 6
step = .01
Scale = 1.2
xscale=1
yscale=.5
x_coords = [t for t in srange(LowerX,UpperX,step)]
y_coords = [((-t^2+t+2)*exp(t)).n(digits=6) for t in srange(LowerX,UpperX,step)]
output = r""
output += r"\begin{tikzpicture}[scale=%f]"%(Scale)
output += r"\begin{axis}["
output += r" grid = both,"
output += r"minor tick num=4,"
output += r"every major grid/.style={Red!30, opacity=1.0},"
output += r"every minor grid/.style={ForestGreen!30, opacity=1.0},"
output += r"height= %f\textwidth,"%(yscale)
output += r"width = %f\textwidth,"%(xscale)
output += r"thick,"
output += r"black,"
output += r"scale=%f,"%(Scale)
output += r"axis lines=center,"
output += r"domain=%f:%f"%(LowerX,UpperX)
output += r"samples=500,"
output += r"xlabel={$\omega,c^{-1}$},ylabel={$M_c,HM$},"
output += r"every axis x label/.style={"
output += r"at={(ticklabel* cs:1.03)},anchor=west,},"
output += r"every axis y label/.style={"
output += r"at={(ticklabel* cs:1.05)},anchor=south,},"
output += r"line join=bevel,"
output += r"xmin=%f,xmax=%f,ymin= %f,ymax=%f]"%(LowerX,UpperX,LowerY, UpperY)
output += r"\addplot[NavyBlue,unbounded coords=jump] coordinates {"
for i in range(0,len(x_coords)-1):
if (y_coords[i])<LowerY or (y_coords[i])>UpperY:
output += r"(%f , inf) "%(x_coords[i])
else:
output += r"(%f , %f) "%(x_coords[i],y_coords[i])
output += r"};"
u = var('u')
f = (-u^2+u+2)*exp(u)
m(u) = diff(f,u,1)
tan_line(u)=m(0)*u+2
x1_coords = [u for u in srange(-2.6,1.8,.01)]
y1_coords = [tan_line(u) for u in srange(-2.6,1.8,.01)]
output += r"\addplot[Peach,unbounded coords=jump] coordinates {"
for i in range(0,len(x1_coords)-1):
if (y_coords[i])<LowerY or (y1_coords[i])>UpperY:
output += r"(%f , inf) "%(x1_coords[i])
else:
output += r"(%f , %f) "%(x1_coords[i],y1_coords[i])
output += r"};"
output += r"\end{axis}"
output += r"\end{tikzpicture}"
\end{sagesilent}
\sagestr{output}
\end{document}
EDIT: I've added code to address axis labels and position. I noted the same problems you did. It's just trial and error looking for a method that works. One thing to mention that can cause problems. Sometimes code doesn't work because a previous attempt to run has corrupted things. You can see that if you click on the Build tab and force LaTeX, Sage, LaTeX. In that case, deleting all the non tex files for the project and running can get it to work. The part of the code cs:1.03 is putting the label going to 103 percent of the x-axis. x-axis to put the label. Try changing that number to .7 or .99 to see how the label moves. I've run into issues trying to format the labels as you did.did. I don't know how to deal with the comma issue.