График графика в C ++ с использованием Tex - PullRequest
0 голосов
/ 25 апреля 2020

У меня есть два массива x и y, и я хотел бы использовать Tex для вывода графика данных, но мой код не отображает правильный график. Любая помощь, чтобы помочь мне в этой проблеме очень ценится.

// function for plotting x and y data 
void Plot(double x[], double y[]) {
    FILE* fp;
    fp = fopen("Plot.tex", "w");

    // construct the plot
    fprintf(fp, "\\documentclass{standalone}\n");
    fprintf(fp, "\\usepackage{pgfplots}\n");
    fprintf(fp, "\\begin{document}\n");
    fprintf(fp, "\\begin{tikzpicture}\n");
    // add a plot 
    fprintf(fp, "\\begin{axis}[\n");
    fprintf(fp, "\\title={Title},\n");
    fprintf(fp, "\\xlabel={xlabel},\n");
    fprintf(fp, "\\ylabel={ylabel},\n");
    fprintf(fp, "\\xmin=%8.4f, xmax=%8.4f,\n", x[0] * .80, x[10] * 1.20);
    fprintf(fp, "\\ymin=%8.4f, ymax=%8.4f,\n", y[0] * .80, y[10] * 1.20);
    fprintf(fp, "\\ymajorgrids=true,\n");
    fprintf(fp, "\\grid style=dashed,\n");
    fprintf(fp, "\\]\n");
    fprintf(fp, "\\addplot gnuplot[id=IV];\n", y);


    // complete the construction 
    fprintf(fp, "\\end{axis}\n");
    fprintf(fp, "\\end{tikzpicture}\n");
    fprintf(fp, "\\end{document}\n");
    fclose(fp);

    return;
}

Вывод: enter image description here

Мой вывод должен быть линейным графиком:

enter image description here

...