Wie erstelle ich PDF mit Latex?

Wie erstelle ich PDF mit Latex?

Entschuldigen Sie die dumme Frage. Ich versuche es gerade, aber ich weiß nichts.

Mein Problem ist: Ich möchte ein Diagramm mit Python-Code zeichnen.

Ich führe es im Terminal aus (ich verwende einen Mac), indem ich Folgendes aufrufe: pdflatex -shell-escape plot_air_drag.tex

! Ich kann die Datei „plot_air_drag.tex“ nicht finden.

<*> plot_luftwiderstand.tex

(Drücken Sie die Eingabetaste, um es erneut zu versuchen, oder Strg-D, um zu beenden.)

Bitte geben Sie einen anderen Eingabedateinamen ein:

Wie wird es ausgeführt?

Hier ist mein 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]
        \addplot table {plotdata1.dat};%
        \addplot[magenta] table {plotdata2.dat};%
    \end{axis}
        \end{tikzpicture}

\end{document}

Antwort1

Funktioniert gut auf Mac mit 10.9.2 und mit pdfTeX, Version 3.1415926-2.5-1.40.14 (TeX Live 2013). Aber:

Speichern Sie die Datei unterplot_air_drag.tex (die Fehlermeldung zeigt an, dass Sie einen anderen Dateinamen verwenden)

Ändern Sie Ihre Präambel

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

Terminal starten,

Geben Sie cd ein Spaceund löschen Sie dieOrdnermit den Dateien dort.

Drücke Enter.

Und verwendenpdflatex -shell-escape plot_air_drag.tex Bildbeschreibung hier eingeben

verwandte Informationen