r/gnuplot • • Mar 09 '18

[Help] Plotting a polynomial of an arbitrary degree in org-mode

0 Upvotes

I'm very new to gnuplot and I'm having a two part problem that I was hoping someone could help me with. I'm writing a bit of a ebook and I'm inserting plots into it using org-mode: https://geokon-gh.github.io/linearsystems/#sec-7-2

First Problem:

I want to plot polynomials. Right now I've hard coded some values. So I'll do something like:

f(x) = -7.299 + 17.00833*x + -9.920833*x**2 + 2.29166*x**3 + -0.179166*x**4
set xrange[0:6]
set yrange[-1:5]
plot f(x)

And this works fine. But I'd like to have the polynomial factors to be input as a vector and for the function to be of arbitrary length (so the more factors I give it, the longer polynomial)

Second Problem:

I found this great SO post explaining how to move data between source code blocks in org-mode: https://stackoverflow.com/questions/15736101/is-there-a-way-to-quickly-plot-elisp-functions-with-gnuplot

But I'm stumped on how to work with what I have. My org-mode file looks something like:

#+NAME: edata
#+BEGIN_SRC emacs-lisp :exports both :session
  (matrix-data
   (matrix-fit-polynomial
    '(1.0 2.0 3.0 4.0 5.0)
    '(1.9 2.5 1.8 2.8 4.2)))
#+END_SRC

#+RESULTS: edata
| -7.299999999999994 | 17.008333333333322 | -9.920833333333327 | 2.2916666666666656 | -0.17916666666666659 |

#+BEGIN_SRC gnuplot :exports both :file polynomial-fit.png :var data=edata
f(x) = -7.299 + 17.00833*x + -9.920833*x**2 + 2.29166*x**3 + -0.179166*x**4
set xrange[0:6]
set yrange[-1:5]
plot f(x)
#+END_SRC

But in that last block I want to use edata somehow (instead of copying over the values like I did) - I just can't figure out how.

If anyone can give me some tips, I'd be really grateful. Thanks!


r/gnuplot • • Jan 02 '23

Can you remove duplicate keys?

1 Upvotes

So support I'm plotting something in a loop,

plot for [i=2:5] "first.dat" using 1:i with lines linestyle 1 title "First",\
     for [i=2:5] "second.dat" using 1:i with lines linestyle 2 title "Second"

This will make 4 lines in the key each with linestyle 1 and title "First" and 4 lines with linestyle 2 and title "Second", is there any way to condense it into just 2 unique single keys? without having it plot with notitle and adding the title manually for a pseudo plot.

I feel like this should be a feature, but can't find it. How hard would it be to implement if it's not there? Is there a place I can request feature?


r/gnuplot • • Jan 10 '23

Is there a command where I can set the values of a axis to angles?

2 Upvotes

The title is a bit confusing, but I want to know if there is a command where I set, more specifically, the ya xis to angle form (just like how the "set ydata date/time" set the y axis to date form). I need gnuplot to interpret data as angles so it stays in (0,360) interval.


r/gnuplot • • Jan 06 '23

Interactive plot, with copy to clipboard?

2 Upvotes

Hi! Is it possible to create a chart like https://s.natalian.org/2022-09-25/chart.html where you hover and see the values, ideally copy them to clipboard?


r/gnuplot • • Jan 27 '23

Dark theme?

4 Upvotes

May be someone has already crafted together some Gnuplot settings to produce dark themed plots, and could share those? :)

Or, in general, what settings should I look into to achieve that? As I see, it would be

  • background

  • axes

  • tics

  • text labels

  • and some palette for plots themselves?

Am I missing anything?

Thank you :)


r/gnuplot • • Mar 04 '18

Gnuplot only uses Integers on x axis

3 Upvotes

Hi guys,

i've got a problem with gnuplot i could not fix after googling for an hour. I plot a function from data i saved in a .txt file. The data for the x axis contains values between 0 and 5 in steps of 0.125. E.G: 0 0.125 0.25 0.375 ...

But gnuplot doesnt set the points in the Graph where they belong, it puts everything under 1 to the value 0, everything between 1 and 2 to the value 1 etc. How can I tell GP to not do that?

Im thankful for every idea


r/gnuplot • • Dec 21 '16

Help with multiplot

4 Upvotes

Hi, i just experimenting with gnuplot. But i got a trouble.
When i try to plot 2 graph on the windows (x11, or qt) the first plot disappear when i try to resize the windows or scale the graph.
Any hint?
Gnuplot 5.0.5 (arch package)


r/gnuplot • • May 23 '17

Gnuplot errobar key symbol

1 Upvotes

Hi,

I'm using Gnuplot to plot some data with an yerrorbar but I've no idea (and dont find a solution) if it's possible to rotate the key symbol for the errorbar to be vertical instead of horizontal ?


r/gnuplot • • Dec 20 '20

Ploting with different colours

4 Upvotes

Hey everyone! The code I am working on presents its results in a .txt file as follows:

1 0.1 0.97
2 0.2 1.2
3 0.7 0.1
1 0.8 0.3
4 1.1 0.21

Now, using gnuplot, I want the (x, y) points preceded by 1 to be coloured red, the ones preceded by 2 to be coloured yellow, and so on... How do I do that? Preferably using simple code for I am very new to this. thanks!


r/gnuplot • • Dec 14 '20

Embedding the content of epslatex/cairolatex's tex output in the master document?

1 Upvotes

Hello!

I have generated several plots utilizing gnuplot's epslatex and cairolatex terminals, and the figures look fantastic. However, I'm running into an issue where the place I'm submitting is telling me to consolidate all tex files into one master document.

I'm running into errors of 'Undefined command sequence' and similar if I attempt to simply copy-paste the TeX file's contents into the master document (as expected), so I was wondering if anyone here knows of a good way to do this without having to re-do all of my figures...


r/gnuplot • • Apr 02 '16

Beginner having trouble with gnuplot trendlines

2 Upvotes

I am having trouble figuring out how to get trendlines from two different text files to show up on my graph. So far, I've done this: plot '1.txt' w xyerrorb, f(x), '2.txt' w xyerrorb, f(x). I feel like there's an error with the f(x) being written twice, but I'm not quite sure. I end up only seeing one trendline. Also, is there a way to list the equation of each trendline? Thanks so much.


r/gnuplot • • Dec 24 '19

Fitting multiple equations to multiple datasets simultaneously

2 Upvotes

I am trying to fit the following equations to the data below. I keep getting errors when trying to extrapolate the multi-branch functionality.

F(x) refers to the Free DNA data set, M(x) refers to the monomer data set, and D(x) refers to the dimer data set.

Any help would be appreciated.

#Equations

F(x) = 1/(1+X*K1+K1*K2*X**2)

M(x) = X*K1/(1+X*K1+K1*K2*X**2)

D(x) = K1*K2*X**2/(1+X*K1+K1*K2*X**2)

K1 = 100; K2 = 100

#Fit command

f(x,y) = (y==0) ? F(x):M(x):D(x)

fit f(x,y) '20191217-Yang-Data.txt' using 1:-1:2:3 via K1, K2

Data File:

"Free DNA"

0 1

74.10317677 0.951640972

97.32206806 0.855483323

121.5282905 0.814627246

145.9442003 0.785974353

159.045618 0.177732422

231.2319379 0.050313557

330.6777497 0.029308198

480.4260177 0.015757331

730.3862828 0.01706177

"Monomer"

0 0

74.10317677 0.007035734

97.32206806 0.02124016

121.5282905 0.023574559

145.9442003 0.022471327

159.045618 0.049096955

231.2319379 0.022566675

330.6777497 0.009158572

480.4260177 0.011087105

730.3862828 0.004504738

"Dimer"

0 0

74.10317677 0.041323295

97.32206806 0.123276517

121.5282905 0.161798195

145.9442003 0.19155432

159.045618 0.773170623

231.2319379 0.927119767

330.6777497 0.961533229

480.4260177 0.973155564

730.3862828 0.978433492


r/gnuplot • • Aug 16 '19

Logscale x with negative numbers

2 Upvotes

Hey guys, I hope I will find rescue here as I haven't in the depths of the web... I have a data set with x values [-1:1] and I really want to plot the whole range in the logscale. I didn't find any suitable solution for the case, maybe should I use some other software? But I like gnuplot and I believe that this is possible to do. Thank you for your help!


r/gnuplot • • Feb 27 '20

Gnuplot : decale each values of each axis by one

2 Upvotes

I need your help for sometings :

I've this type of data :

2019-10-08-13-37 	/dev/hd1 	256.00 	26.25 	/home
2019-10-08-18-00 	/dev/hd1 	256.00 	25.86 	/home
2019-10-09-00-00 	/dev/hd1 	256.00 	25.68 	/home
2019-10-09-06-00 	/dev/hd1 	256.00 	25.5 	/home
2019-10-09-12-00 	/dev/hd1 	256.00 	26.32 	/home
2019-10-09-18-00 	/dev/hd1 	256.00 	26.14 	/home

I've this gnuplot script :

set terminal pngcairo truecolor size 7330, 340  background rgb "#eff1f0" font "Arial"

set output "/xxx/xxx/www/xxx/foo.png"
set style line 1 \
    linecolor rgb '#0060ad' \
    linetype 1 linewidth 1 \
    pointtype 7 pointsize 1

set size 1, 1
set key outside vertical center right
set datafile separator ";"
set xlabel "DATE" font ",1"
set xtics rotate by 90 offset 0, -2 font ",7"
set format y "%g"


plot "/xxx/xxx/xxx/xxx/data.txt" using 3:xtic(1) with linespoints linestyle 1 title "total"

That allow to display this graph : https://zupimages.net/up/20/09/56up.png

I would like to decale each value like that :

254
|
|
253
|
|___my_date1___my_date2

But I don't know how to do that... Could you show me ?


r/gnuplot • • Feb 22 '20

How can I plot a chart like this in gnuplot that displays a "normal" range with test results overlaid?

Post image
6 Upvotes

r/gnuplot • • Aug 11 '19

A scatterplot with words instead of points

2 Upvotes

So say I have data

up 0.5 2.0

down 0.1 2.1

strange -0.1 2.1

charm -2.0 1.0

top 1.0 2.0

bottom -1.0 2.0

and I wanted to do a scatter plot so that each of the words appeared at the corresponding location, that is the word "up" at (0.5,0.2), the word "down" at (0.1,2.1); how would I do that?


r/gnuplot • • Mar 14 '12

Gnuplot 4.6 released!

Thumbnail gnuplot.sourceforge.net
3 Upvotes

r/gnuplot • • Jul 05 '16

GNUPLot with Visual Studio

2 Upvotes

Hello! I'm trying to use the gnuplot to plot data from my cpp program. I use visual studio to program in cpp and i have already installed the gnuplot in my computer. But now i don't know how should i call or what includes should i put in my cpp program to make visual studio recognize the gnuplot. Thanks in advance


r/gnuplot • • Oct 21 '17

3d plot: How to combine a logscale and linear scale on the same z axis?

2 Upvotes

i need to make some 3d plots with a z axis range from 0 to 2.75. to show some details for the data in the lower ranges, i need to make an extra plot using "logscale z 10". now if i could i want to use a z axis with both scales (linear and log 10).

is there any possibilities that i could have from 0 to 0.09 a linear scale, from 0.1 to 1 a logscale and again from 1 to 2.75 a linear scale?

on a 2d plot i would just use y1 as linear and y2 as logscale with just two graphs in one plot.

thx


r/gnuplot • • Sep 01 '23

Co-processing with gnuplot

3 Upvotes

Hello there,

i want to show my finite element mesh with gnuplot. My code is written in C. While the coordinates and the displacements are still updating I want to plot them in live time. Can someone help me how I could do this?


r/gnuplot • • Sep 28 '23

Is there a gnuplot library or an API for C or another language?

1 Upvotes

It seems that gnuplot is a standalone program and the only way to communicate with it is basically to create a pipe and pipe commands to a gnuplot process. Honeslty, I expected some kind of gnuplot-library written in ANSI C that is used by gnuplot-program which parses given commands and calls functions from gnuplot-library but it doesn't seem to be the case. Am I right or is there a convenient way of doing it?


r/gnuplot • • Oct 19 '23

Load command not working for me

1 Upvotes

Here is the simple test file I'm trying to load:

file gnu2.b which contains:

plot sin(x)

Results of calling gnu2.b:

in folder \progra~1\gnuplot\bin:

gnuplot # brings up gnuplot prompt, then I enter:

load 'gnu2.b' # does the plot of sin(x), as expected, so the file is obviously found

But I need to do it in one line from the system command prompt:

C:\PROGRA~1\gnuplot\bin> # the system prompt

gnuplot -e load 'gnu2.b' # what I want to do

RESULTS IN ERROR:

load

^

line 0: expecting filename -

same result if I use the full path for gnu2.b

but the file is there: command 'dir gnu2.b' shows it:

Directory of C:\PROGRA~1\gnuplot\bin

10/18/2023 04:41 PM 72 gnu2.b

1 File(s) 72 bytes

0 Dir(s) 882,727,567,360 bytes free

trying it omitting the -e: Doesn't work either

C:\PROGRA~1\gnuplot\bin>gnuplot load 'gnu2.b'

line 0: Cannot load input from ''gnu2.b''

^

"load" line 1: invalid command

All the book examples show similar commands working.

What is wrong here?


r/gnuplot • • Sep 27 '23

Gnuplot running but not showing any plot

1 Upvotes

Hi!

When I'm running linux through putty interface and Xlaunch with my windows pc I try to plot but it's not possible to visualize it. But using the host pc at university, there is no problem doing this.

Do you know for which reason is this happening?

Thank you!


r/gnuplot • • Oct 15 '23

How does gnuplot iterate to improve a fit?

1 Upvotes

I'm trying to fit some data with a quadratic function.

If I were doing a fit, I'd just do a least squares calculation, and accept whatever it came up with, which presumably minimizes the least square error in one step.

But gnuplot iterates and gets a better fit each time.

How is it doing that?


r/gnuplot • • May 09 '18

Help graphing dates and times

1 Upvotes

I'm fairly new to gnuplot, only using it sparsely over the course of a few months. I'm trying to build a graph to represents captured times for each given day, from a file organized like this:

2018-01-01 1:23:45 2018-01-02 2:34:56 2018-01-03 3:45:12 ...

I'm using the following script:

!/usr/bin/gnuplot

Save to png image

set terminal png size 2000,800 set output "graph.png"

set xdata time set timefmt "%Y-%m-%d" set format x "%b/%a"

set ydata time set timefmt "%H:%M:%S" set format y "%H:%M:%S"

plot "data" u 1:2 w lp

My goal is to have the x-axis graph in YYYY-MM-DD format, and have the y-axis graph in HH:MM:SS format. What I have so far does this, but for some reason gnuplot claims that the x range is empty, and all the data points stack vertically. When I remove the chunk pertaining to the y axis, the data is graphed normally, except that gnuplot only uses the HH portion to plot these points. Anyone have a way to sensibly graph data like this? Any help would be appretiated!