# How to create pdf with latex?

Sorry about asking a stupid question. I'm just trying to use this, but don't know anything.

My problem is: I want to plot graph with python code.

I run it in terminal (I'm using mac) by calling: pdflatex -shell-escape plot_air_drag.tex

! I can't find file plot_air_drag.tex'.

<*> plot_air_drag.tex

(Press Enter to retry, or Control-D to exit)

Please type another input file name:

What is the way to run it?

Here is my code:

\documentclass[a4paper]{book}
\usepackage{pgfplots}
\usepackage{python}

\pagestyle{empty}

\begin{document}

\begin{python}
from pylab import *
from scipy.integrate import odeint
from functools import partial

## set initial conditions and parameters
g = 9.81            # acceleration due to gravity
th = 45.            # set launch angle
th = th * np.pi/180.   # convert launch angle to radians
v0 = 20.0           # set speed

x0=0                # specify initial conditions
y0=0
vx0 = v0*sin(th)
vy0 = v0*cos(th)

## define function to compute f(X,t)
def f_func_k(k,state,time):
f = zeros(4)    # create array to hold f vector
f[0] = state[2] # f[0] = x component of velocity
f[1] = state[3] # f[1] = x component of velocity
f[2] = - k*(f[0]**2 + f[1]**2)**(0.5)*f[0]         # f[2] = acceleration in x direction
f[3] = -g - k*(f[0]**2 + f[1]**2)**(0.5)*f[1]       # f[3] = acceleration in y direction
return f

def gen_plot_data(s,k):
f_func = partial(f_func_k,k)

## set initial state vector and time array
X0 = [ x0, y0, vx0, vy0]        # set initial state of the system
t0 = 0.
# tf = input("Enter final time: ")
# tau = input("Enter time step: ")
tf = 3
tau = 0.05

# create time array starting at t0, ending at tf with a spacing tau
t = arange(t0,tf,tau)

## solve ODE using odeint
X = odeint(f_func,X0,t) # returns an 2-dimensional array with the
# first index specifying the time and the
# second index specifying the component of
# the state vector

# putting ':' as an index specifies all of the elements for
# that index so x, y, vx, and vy are arrays at times specified
# in the time array
x = X[:,0]
y = X[:,1]
vx = X[:,2]
vy = X[:,3]

xy = zip(x,y)
np.savetxt(s,xy,fmt='%0.5f')

gen_plot_data("plotdata1.dat",0.04)
gen_plot_data("plotdata2.dat",0)
\end{python}

\begin{tikzpicture}
\begin{axis}[no marks,samples=100,axis lines=center,xlabel=$x$,ylabel=$y$,enlargelimits]
\end{axis}
\end{tikzpicture}

\end{document}

• Are you in the correct directory? You need to change to the path where the .tex file is located. Mar 19 '14 at 12:51
• Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. Mar 20 '14 at 9:42

Works fine on Mac with 10.9.2 and with pdfTeX, Version 3.1415926-2.5-1.40.14 (TeX Live 2013). But:

Save your file as plot_air_drag.tex (the error message indicates you are using an different file name)

\documentclass[a4paper]{book}
\usepackage{pgfplots}
\pgfplotsset{compat=1.10}
\usepackage{python}


Start Terminal,

Type cd Space` and drop the folder with the files there.

Hit Enter.

And use pdflatex -shell-escape plot_air_drag.tex