Data disappears when logscale is used in gnuplot - scale

I have successfully made a nice looking histogram in gnuplot with a normal scale but when I add
set logscale y
to my code, the data disappears.
I discovered that logscale does not work with the function I am using to make the histogram (shown in the following link).
https://stackoverflow.com/a/2538846/2506689
Does anyone have any suggestions on how to fix this?

set table to the rescue!
Note that I typed all of this into the interactive prompt and copy/pasted my terminal contents. As such, my commands that follow are prefixed by a gnuplot> which you won't include in your script :-)
First, I generate some data using python ...
import numpy as np
np.savetxt('foobar.txt',np.random.random(1000))
That wasn't hard. Now time to set up gnuplot functions/constants:
gnuplot> binwidth = 0.05
gnuplot> bin(x,width)=width*floor(x/width)
gnuplot> plot 'foobar.txt' using (bin($1,binwidth)):(1.0) smooth freq with boxes
Ok, it works with non-logscale data. That's good. Lets write that data into a separate file using set table
gnuplot> set table 'foobar.table'
gnuplot> plot 'foobar.txt' using (bin($1,binwidth)):(1.0) smooth freq with boxes
gnuplot> unset table
Now I look at the data gnuplot wrote out to see what's there.
gnuplot> !head foobar.table
# Curve 0 of 1, 21 points
# Curve title: "'foobar.txt' using (bin($1,binwidth)):(1.0)"
# x y xlow xhigh type
0 40 0 0 i
0.05 57 0.05 0.05 i
0.1 52 0.1 0.1 i
0.15 56 0.15 0.15 i
0.2 49 0.2 0.2 i
0.25 55 0.25 0.25 i
Unfortunately, it looks like xlow and xhigh are always the same (possible bug?). But that's Ok, we're using a constant binwidth anyway. We'll just use that as the width.
gnuplot> set logscale y
gnuplot> plot 'foobar.table' u 1:2:(binwidth) w boxes
I should note that I've been a little loose with my box positions. To really get it right, you probably need to shift the center of the boxes to the right by half a binwidth:
gnuplot> plot 'foobar.table' u ($1+0.5*binwidth):2:(binwidth) w boxes

Related

Using gnuplot to plot points with color and x-marks

I have been trying this for a few hours but I am not getting anywhere.
What I am trying to do is this:
I have a solution from a simulation with x and y values and a value for each point.
I am trying to plot the data using gnuplot. I want the values in between my data points to be interpolated using color and the points themself shall be marked with a dot, a "x" or sth. like that similar to this (except for the round border and those labels inside):
I have been trying to get a very basic example going. My data file looks like this:
1 1 0.1
1 2 0.3
1 3 0.6
2 1 0.5
2 2 0.7
2 3 0.9
3 1 0.2
3 2 0.8
3 3 0.7
and my gnuplot input like this:
set terminal postscript eps enhanced color font 'Helvetica,10'
set output './production/image1.eps'
set palette gray
set title "Titel"
#set xrange [1:4]
#set yrange [0:10]
set format y "%.1f"
set format x "%.1f"
set xlabel "x-Achse [Einheit]"
set ylabel "y-Achse [Einheit]" rotate by 90
set view map
set pm3d at b map
set pm3d interpolate 2,2
set dgrid3d 50,50,2
splot "inputDatei.dat" u 1:2:3 linecolor palette
The result looks like this:
There are a few issues with this which i cannot resolve:
there is a label in the rip right "inputDatai.dat" u 1:2:3". I tried splot ... label "" but this didnt solve the issue
the interpolation doesnt seem to work. this is visible with a smaller grid
the data points are not highlighted. I tried using splot ... with points but this would only display points at EVERY grid corner which is obviously way too much. Also the input data might not be "regular" but points can be anywhere.
I am very happy if someone could help me with this.
Greetings,
Finn
To your questions:
use unset key before the plot command or splot ... notitle within the plot command
what "does not work" mean? Please explain.
I guess that's similar to here (Superimposing vectors, dgrid3d and pm3d in gnuplot for 3D plot). You have to switch off interpolating for the highlighted points. I'm not sure whether this can be done within a plot command, so you have to plot the interpolated data into a separate datablock via set table and then switch off interpolation.
Code:
### interpolate data with highlighted datapoints
reset session
$Data <<EOD
1 1 0.1
1 2 0.3
1 3 0.6
2 1 0.5
2 2 0.7
2 3 0.9
2.5 2.5 0.1
3 1 0.2
3 2 0.8
3 3 0.7
EOD
set size square
set view map
set pm3d at b
set pm3d interpolate 2,2
set dgrid3d 50,50,2
set table $DataInterpolated
splot $Data u 1:2:3
unset table
unset dgrid3d
set palette grey
set xrange [0.9:3.1]
set yrange [0.9:3.1]
splot $DataInterpolated u 1:2:3 w pm3d palette notitle, \
$Data u 1:2:3 w p pt 1 lw 2 lc rgb "red" notitle
### end of code
Result:

Gnuplot: plotting results from different sources in one graph

I am trying to compare the results of a measurement from different collaborations using gnuplot. The plot should ideally look like this:
I can't figure out how to plot the different results one on top of the other, with the labels on the right. I would be really grateful if anyone could help me.
I show two approaches, depending of your data file. Two possible structures are data01.dat
# data01.dat
alpha error
1.0 0.2
2.0 0.2
1.5 0.2
or data02.dat
# data02.dat
Collab alpha error
1 1.0 0.2
2 2.0 0.2
3 1.5 0.2
Using the data01-structure:
reset
set encoding utf8
set terminal wxt size 480,600 font "Times New Roman,10"
set tics out nomirror
set xlabel "{/:Italic=12 α}"
set link y2
unset ytics
set y2range [:] reverse
set y2tics 1
set format y2 "Collaboration %g"
set offsets graph 0.1, 0.1, 0.5, 0.5
plot "data01.dat" u 1:0:2 w xerrorbars pt 7 not
Using the data02-structure almost all is the same, except the plot command.
plot "data02.dat" u 2:1:3 w xerrorbars pt 7 not
The results.
I hope be useful.

Gnuplot filled curves not showing properly

I am trying to plot a filled curve with Gnuplot. If I set the Y range to a large value, the filled curve is plotting just fine. However, when I use a small Y range, some part of the curve are not filling with colors.
set terminal postscript color size 3.25,3.25 font "Helvetica, 8"
set output "test.ps"
set key at screen 0.95,0.70 right bottom
set border lt 1 lc 0 lw 1
set lmargin at screen 0.25
set rmargin at screen 0.95
set tmargin at screen 0.675
set bmargin at screen 0.15
set xlabel "X"
set ylabel "Y"
set xr [-1:2]
set yr [0:160]
set format x "%2.1f"
set style fill transparent solid 0.4
plot "data" w filledcurve x1 lt 1 lw 0.1 lc rgb "red"
This figure is the one with large Y range which is just fine.
This one is the figure with small Y range which is not plotting well.
The data file is available here. https://drive.google.com/drive/folders/1OIHLT2Mz4QGX3VKeZCGM_S4VjTO0FuOc?usp=sharing
Any comment or solution would be appreciated. Thank you all!
No such problem in gnuplot version 5 (confirmed back to version 5.0 patchlevel 3).
Output from current 5.2.4 shown.

take the last data column with AWK to create a linepoints gnuplot

I am working on gnuplot linepoints to create a comulative and normal distribution graph. I have created a file to provide the information to both graphs.
I got a problem when I was trying to plot the last data.
Here is the my script to create the second graph.
plot.plt
set term pos eps
set style data linespoints
set style line 1 lc 8 lt -1
set size 1,1
set yr [0:20]
set key below
set grid
set output 'output.eps'
plot "<awk '{i=i+$3; print $1,i}' data.dat" smooth cumulative t 'twitter' ls 1
data.dat
5.0 1 0.10
9.0 5 0.20
13.0 7 0.30
14.0 1 0.20
15.0 9 0.20
I want to create x axis with the first column and y axis with the last column. so the y axis range must between 0 to 1. which part should I change? thanks
Using smooth cumulative is enough, no need for awk. You are doing the same operation twice, once with gnuplot and once with awk. Simply do
plot 'data.dat' using 1:3 smooth cumulative

Gnuplot---clustered rowstacked bars

How can I make clustered rowstacked bars in gnuplot? It know how to get a clustered bars, but
not a cluster of rowstacked bars. Thanks!
Edit: in a cluster, stacked bars should use different colors/patterns as well.
I'm not completely sure how to go about doing this, but, one idea is to make it so that the boxes are touching each other
`set boxwidth 1`
That doesn't quite get you a "clustered" look yet -- To get a clustered look, I think you'd need to insert a row (maybe column) of zeros...(I haven't sorted through that one in my head yet) into your datafile where you want a cluster break.
Of course, you wouldn't need to set the boxwidth either I suppose...clustered just depends on the breaking every once in a while...
If I understand the original post right, it should be easy to accomplish with gnuplot if you can preprocess your data to offset x coordinates of specific data series.
To illustrate the approach I will use the following data in 3 data series:
# impulse.dat
0.9 1
1.9 4
2.9 3
3.9 5
1.0 1
2.0 2
3.0 4
4.0 2
1.1 3
2.1 3
3.1 5
4.1 4
Here each series has x-coordinates shifted by .1. To plot it I choose impulses of width 10.
plot [0:5] [0:6] 'impulse.dat' ind 0 w imp lw 10, \
'impulse.dat' ind 1 w imp lw 10, \
'impulse.dat' ind 2 w imp lw 10
Edit: to combine this with Matt's suggestion to use boxes would definitely be better:
set boxwidth 0.1
set fill solid
plot [0:5] [0:6] 'impulse.dat' ind 0 w boxes,\
'impulse.dat' ind 1 w boxes, \
'impulse.dat' ind 2 w boxes
Following is the picture with impulses.

Resources