Ask Your Question
0

How to join function to grid scale?

asked 2015-01-29 20:48:04 +0100

y023rus gravatar image

updated 2015-01-29 20:57:35 +0100

Dear friends, I'm trying to use latex+sagetex+tikz and it's really powerfull combination. But I don't understand how to join axes grid to function. If you see attached example you see first original plotting then another two with different axes grids. But function plot in 2,3 graphs the same as in first function plot! It should to stretch/collapse in accord with scale x/y axes. How to do it right way?

Update: I don't know why I can't to add .tex file so you can get this example from http://www.highschoolmathandchess.com... (section "Sagetex and the tkz-fct package"). Changing axes doesn't affect to function plot.

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
0

answered 2015-01-30 05:40:59 +0100

dazedANDconfused gravatar image

updated 2015-01-30 18:03:24 +0100

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 ... (more)

edit flag offensive delete link more
0

answered 2015-01-30 10:04:41 +0100

y023rus gravatar image

updated 2015-01-30 20:34:03 +0100

Excellent. That's very close to what I need. But there are some problems.

  1. I've redefine dot (.) in sage calculations to comma (,) and have x,(y) instead of x.(y) as it's rule in Russia. But on axes numbers again with dot separator.
  2. Fully frustrating with axes label and it's position. I need, for example, two labels: xlabel=$\omega$, c\textsuperscript{-1} and ylabel = {\textit{$M_c$,Нм}} - it doesn't work. Works only xlabel={$\omega$}, ylabel={$M_c$} but labels appeared in weird places. And my attemptions to move it with pgfplot commands nothing to bring. Is it possible to correct it? Especially labels positions?

added: thanks to your help we are have vigorous plotting engine with admirable/professional/harmonic view of plottings. For me I've corrected ylabel={$M_c,HM$} to ylabel={$M_c,\textit{Hм}$} because I need italic low case "м"-meter. I've met with problems you told. I deleted all files with sage in its names and rebuild again. Deep gratitude.

edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 2015-01-29 20:48:04 +0100

Seen: 682 times

Last updated: Jan 30 '15