Gnuplot - Сохраните результат

Я создаю график, который изменяет каждое второе использование gnuplot. Теперь, я хочу сохранить этот график как gif или png файл, когда моя программа заканчивается. Как я могу сделать? Мой код C ниже

FILE *pipe = popen("gnuplot -persist", "w");

// set axis ranges
fprintf(pipe,"set xrange [0:11]\n");
fprintf(pipe,"set yrange [0:]\n");
int b = 5;int a;
// to make 10 points
std::vector<int> x (10, 0.0); // x values
std::vector<int> y (10, 0.0); // y values
for (a=0;a<5;a++) // 10 plots
{
    x[a] = a;
    y[a] = 2*a;// some function of a
    fprintf(pipe,"plot '-'\n");
    // 1 additional data point per plot
    for (int ii = 0; ii <= a; ii++) {
        fprintf(pipe, "%d %d\n", x[ii], y[ii]); // plot `a` points
    }

    fprintf(pipe,"e\n");    // finally, e
    fflush(pipe);   // flush the pipe to update the plot
    usleep(1000000);// wait a second before updating again
}
2
задан 17 December 2014 в 02:38

1 ответ

Я не войду в c (который кажется действительно C++), часть---, просто необходимо отправить корректную команду в gnuplot.

Изменение выходного формата называют, изменяя терминал в gnuplot.

Например, для генерации файла PNG, в gnuplot:

[...instruction to make youtr graph...]
set term pngcairo
set output "filename.png"
replot
set output 

... генерирует диаграмму в названном файле filename.png. Не забудьте переключаться назад на свой терминал (или использовать другой экземпляр gnuplot) с чем-то на стиле

set term wxt persist 

прежде, чем вывестись на печать снова.

У Вас есть большая информация в help set term pngcairo:

gnuplot> help set term pngcairo
 The `pngcairo` terminal device generates output in png. The actual
 drawing is done via cairo, a 2D graphics library, and pango, a library for
 laying out and rendering text.

 Syntax:
         set term pngcairo
                      {{no}enhanced} {mono|color} {solid|dashed}
                      {{no}transparent} {{no}crop} {background <rgbcolor>
                      {font <font>} {fontscale <scale>}
                      {linewidth <lw>} {rounded|butt} {dashlength <dl>}
                      {size <XX>{unit},<YY>{unit}}

 This terminal supports an enhanced text mode, which allows font and other
 formatting commands (subscripts, superscripts, etc.) to be embedded in labels
 and other text strings. The enhanced text mode syntax is shared with other
 gnuplot terminal types. See `enhanced` for more details.

Существуют терминалы для генерации битового массива в большом количестве форматов: просто посмотрите на

help set term jpeg
help set term gif

В gif режим можно даже генерировать анимированный gif. См.:

gnuplot> set term gif animate
Terminal type set to 'gif'
Options are 'nocrop font "/usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf,12" fontscale 1.0 animate delay 10 loop 0 nooptimize size 640,480 '
gnuplot> set output "test.gif"
gnuplot> plot sin(x)
gnuplot> plot sin(x-1)
gnuplot> plot sin(x-2)
gnuplot> plot sin(x-3)
gnuplot> plot sin(x-4)
gnuplot> plot sin(x-5)
gnuplot> set output 
End of animation sequence

... и Вы имеете в test.gif:

Animated gif of sin(x)

1
ответ дан 2 December 2019 в 05:09

Другие вопросы по тегам:

Похожие вопросы: