Duplicate output rows - gnuplot

I tried to plot this dataset, but got extra lines on the output.
Here is my dataset, feedings.data:
2023-01-22 09:00
2023-01-22 11:40
2023-01-22 13:30
2023-01-22 19:40
2023-01-22 22:15
2023-01-23 04:45
2023-01-23 07:45
2023-01-23 10:15
2023-01-23 12:30
2023-01-23 13:30
2023-01-23 17:45
2023-01-23 22:45
2023-01-24 02:45
2023-01-24 07:30
2023-01-24 10:30
2023-01-24 13:30
2023-01-24 17:45
Here is a simplified version of my gnuplot program:
reset
set output "./feedings.png"
set xdata time
set format x "%H:%M"
set ytics time;
set format y "%Y-%m-%d"
plot "./feedings.data" using (timecolumn(2, "%H:%M")):(timecolumn(1, "%Y-%m-%d")) with points;
Here is the output:
How can I get rid of the superfluous empty lines on the y axis?

Short answer:
set ytics 86400
unset mytics
Set the major ytic distance manually, i.e. 86400 seconds are one day.
If your y-range is more than just 2 or 3 days the gnuplot auto-tics should reduce the number of major tics automatically.
Remove the minor ytics via unset mytics.
I would use the newer syntax without set xdata time, but set format x "%H:%M" timedate and set format y "%Y-%m-%d" timedate.
Script:
### customize timedate format ytics
reset session
$Data <<EOD
2023-01-22 09:00
2023-01-22 11:40
2023-01-22 13:30
2023-01-22 19:40
2023-01-22 22:15
2023-01-23 04:45
2023-01-23 07:45
2023-01-23 10:15
2023-01-23 12:30
2023-01-23 13:30
2023-01-23 17:45
2023-01-23 22:45
2023-01-24 02:45
2023-01-24 07:30
2023-01-24 10:30
2023-01-24 13:30
2023-01-24 17:45
EOD
set format x "%H:%M" timedate
set format y "%Y-%m-%d" timedate
set offsets 0,0,0.5,0.5
set ytics 86400
unset mytics
plot $Data u (timecolumn(2, "%H:%M")):(timecolumn(1, "%Y-%m-%d")) \
w p pt 7 lc "red" ti "Data"
### end of script
Result:

Related

gnuplot: how to plot color squares for each month's temperature?

I would like to plot the following figure (from Fundamentals of Data Visualization) using gnuplot:
I expect the data for each location is something like:
# month temperature
01 60.0
02 78.0
03 90.0
...
12 78.0
Here is what I tried. For simplicity, I have transposed the data into a matrix.
$data << EOD
1.50 1.57 1.85 2.15 1.87 1.05 1.70 1.65 1.97 1.71 1.53 1.15
4.44 4.71 4.74 3.50 3.43 4.98 4.29 4.55 3.93 3.34 3.74 4.88
8.55 9.59 5.65 0.13 9.33 4.70 8.94 7.74 4.49 6.26 0.96 1.20
EOD
unset border
unset ytics
set xlabel 'month'
set palette rgbformula -7,2,-7
set cbrange [0:10]
set cblabel "precipitation"
set xrange [-0.5:11.5]
set yrange [-0.5:2.5]
set xtics ("Jan" 0, "Feb" 1, "Mar" 2, "Apr" 3, "May" 4, \
"Jun" 5, "Jul" 6, "Aug" 7, "Sep" 8, "Oct" 9, "Nov" 10, "Dec" 11)
plot $data matrix with image
But the effect is far from satisfactory. For example, How to generate clear borders between squares?
The plotting style with image probably cannot have borders. So, I would use the versatile style with boxxyerror.
Furthermore, instead of matrix format I would add a line header and loop through the columns (since there will be always 12 months)
Check the following example as well as help boxxyerror, help size, help xticlabels and help strftime for further reading.
If you have your data in separate files you would have to modify the script accordingly.
Script:
### plotting style boxxyerror as replacement for "with image"
reset session
$Data << EOD
# location Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
Atlantis 1.50 1.57 1.85 2.15 1.87 1.05 1.70 1.65 1.97 1.71 1.53 1.15
Mordor 4.44 4.71 4.74 3.50 3.43 4.98 4.29 4.55 3.93 3.34 3.74 4.88
Wonderland 8.55 9.59 5.65 0.13 9.33 4.70 8.94 7.74 4.49 6.26 0.96 1.20
EOD
unset border
set xlabel 'month'
set xrange [0.5:12.5]
set yrange [:] reverse
set ytics
set palette rgbformula -7,2,-7
set cbrange [0:10]
set cblabel "precipitation"
MonthName(n) = strftime("%b",24*3600*28*n) # get the month name from 1..12
set key noautotitle
set style fill solid 1.0 border rgb "white"
set size ratio -1 # make the boxes squares
plot for [i=1:12] $Data u (i):0:(0.5):(0.5):i+1: \
xtic(MonthName(i)):ytic(1) w boxxy fc palette lw 2
### end of code
Result:

y2tics and y2label missing in the pm3d map

I am trying to plot a pm3d map using both the primary and secondary axes of gnuplot (version 5.2 patchlevel 8). However, the y2label is missing and the y2tics do not appear after three marks. It would be very helpful if anyone can kindly point out any mistake I have made. The script used is given below and the figure obtained is attached for your reference.Thank you in advance.
set term postscript
set output "map.ps"
set pm3d map corners2color c1
set palette maxcolors 8
set palette defined (0 "#FFFFFF", 1 "#FFFF00", 2 "#FFC020", 3 "#FF69B4", 4 "#4169E1", 5 "#008000", 6 "#20B2AA", 7 "#9ACD32")
set lmargin at screen 0.095
set rmargin at screen 0.795
unset key
# set x-axis
#*******************************************************
set xlabel "Time (ns)" font "Times-italic,18" offset 0, -0.5, 0
set xrange [0.000: 7500.000]
set xtics ("0" 0.000, "50" 1250.0, "100" 2500.0, "150" 3750.0, "200" 5000.0, "250" 6250.0, "300" 7500.0) font "Times-italic,16"
# set y-axis
#*******************************************************
set ylabel "Peptide Number" font "Times-italic,18" offset -1.2, 1, 0
set yrange [2.0: 36.0]
set ytics ("1" 5.0, "2" 12.0, "3" 19.0, "4" 26.0, "5" 33.0) font "Times-italic,16"
set ytics nomirror
set y2label "Residue Number" font "Times-italic,18" offset -2.5, 0, 0
set y2range [2.0: 36.0]
set y2tics nomirror ("1" 2.0, "7" 8.0, "1" 9.0 , "7" 15.0, "1" 16.0, "7" 22.0, "1" 23.0, "7" 29.0, "1" 30.0, "7" 36.0) font "Times-italic,14"
# set cb-axis
#*******************************************************
set colorbox vertical user origin 0.890, .147 size .04, .73
set cbrange [-0.500: 7.500]
set cbtics 0.000, 7.000, 1.0
set cbtics("None" 0.000,"Ext" 1.000,"Bridge" 2.000,"3-10" 3.000,"Alpha" 4.000,"Pi" 5.000,"Turn" 6.000,"Bend" 7.000)
set link y2
splot "-" with pm3d title "map.gnu"
1.000 1.000 2
1.000 2.000 0
1.000 3.000 0
1.000 4.000 0
1.000 5.000 0
1.000 6.000 3
1.000 7.000 0
1.000 8.000 0
1.000 9.000 0
1.000 10.000 0
1.000 11.000 0
1.000 12.000 0
1.000 13.000 0
1.000 14.000 1
1.000 15.000 0
1.000 16.000 0
1.000 17.000 6
1.000 18.000 0
1.000 19.000 7
1.000 20.000 0
1.000 21.000 0
1.000 22.000 4
1.000 23.000 0
1.000 24.000 0
1.000 25.000 6
1.000 26.000 6
1.000 27.000 5
1.000 28.000 0
1.000 29.000 0
1.000 30.000 4
1.000 31.000 0
1.000 32.000 0
1.000 33.000 7
1.000 34.000 0
1.000 35.000 0
1.000 36.000 0
2.000 1.000 0
2.000 2.000 0
2.000 3.000 0
2.000 4.000 2
2.000 5.000 4
2.000 6.000 5
2.000 7.000 0
2.000 8.000 0
2.000 9.000 6
2.000 10.000 0
2.000 11.000 0
2.000 12.000 0
2.000 13.000 7
2.000 14.000 0
2.000 15.000 0
2.000 16.000 0
2.000 17.000 0
2.000 18.000 0
2.000 19.000 8
2.000 20.000 0
2.000 21.000 0
2.000 22.000 0
2.000 23.000 0
2.000 24.000 9
2.000 25.000 6
2.000 26.000 6
2.000 27.000 6
2.000 28.000 0
2.000 29.000 5
2.000 30.000 0
2.000 31.000 0
2.000 32.000 0
2.000 33.000 7
2.000 34.000 0
2.000 35.000 0
2.000 36.000 0
I assume from your code that you have simple x,y,z data.
x with sample numbers from 0 to 7500 which correspond to 0 to 300 ns.
y in the range from 1 to 6
z in the range from 0 to 7
For the example below I create some random test data.
I can reproduce your issue with splot ... with pm3d, however, do not (yet) have a solution.
Therefore, my suggestion would be to use plot ... with boxxerror.
If you plot that many boxes, your PostScript file probably will get pretty large. So, I would recommend to use a pixel graphic with sufficient resolution, e.g. set term pngacairo size 1400,1000.
Code:
### "plot ... with boxxyerror" instead of "splot ... with pm3d"
reset session
set palette maxcolors 8
set palette defined (0 "#FFFFFF", 1 "#FFFF00", 2 "#FFC020", 3 "#FF69B4", 4 "#4169E1", 5 "#008000", 6 "#20B2AA", 7 "#9ACD32")
# create some random test data
set print $Data
do for [i=1:7500] for [j=1:5] {
print sprintf("%g %g %g", i, int(rand(0)*6)+(j-1)*7+2, int(rand(0)*8))
}
set print
set xrange [0:300]
XScale = 300/7500. # scaling between sample and x-axis units
set yrange [1: 37]
set for [i=1:5] ytics (sprintf("%g",i) i*7-2)
set ytics nomirror
set y2range [1: 37]
set for [i=1:5] y2tics ("1" i*7-5, "7" i*7+1)
set y2tics nomirror
set link y2
set cbrange [-0.500: 7.500]
set cbtics 0.000, 7.000, 1.0
myCbTics = "None Ext Bridge 3-10 Alpha Pi Turn Bend"
set for [i=0:words(myCbTics)] cbtics (word(myCbTics,i+1) i)
set key noautotitle
set tics out
set style fill solid 1.0
plot $Data u ($1*XScale):2:($1*XScale):(($1+1)*XScale):($2):($2+1):3 w boxxy palette z
### end of code
Result:
I do not know why the default link command set link y2 is failing, but it seems to work if you explicitly give the longer form set link y2 via y inv y.
Aside from that, note that set link y2 command will immediately replace any limits on y2range with limits matching the y1 range, so the set y2range command in your script as shown has no effect.

I'm trying to find the last column with data in each row and return the column name to the data frame

I'm trying to get the column name the value from ffill is from.
I've searched google and stack overflow and haven't found a way to accomplish this.
This is the ffill code:
df["LAST_PUNCH"] = df.ffill(axis=1).iloc[:, -1]
This is my dataframe:
SHIFT IN OUT IN_1
DA6-0730 07:30 12:35 13:05
DB0-ACOM 08:18 12:30
DC4-0730 07:30 12:39 13:09
DC4-0730 07:30 12:34 13:04
This is my dataframe after using ffill:
SHIFT IN OUT IN_1 LAST_PUNCH
DA6-0730 07:30 12:35 13:05 13:05
DB0-ACOM 08:18 12:30 12:30
DC4-0730 07:30 12:39 13:09 13:09
DC4-0730 07:30 12:34 13:04 13:04
I would like to get the column name where the ffill value came from and
append to the end of the ffill value:
SHIFT IN OUT IN_1 LAST_PUNCH
DA6-0730 07:30 12:35 13:05 13:05_IN_1
DB0-ACOM 08:18 12:30 12:30_OUT
DC4-0730 07:30 12:39 13:09 13:09_IN_1
DC4-0730 07:30 12:34 13:04 13:04_IN_1
Ummm this is a little bit tricky
(df+'_'+pd.DataFrame(dict(zip(df.columns.values,df.columns.values)),index=df.index)).\
reindex(columns=df.columns).ffill(axis=1).iloc[:,-1]
Out[360]:
0 13:05_IN_1
1 12:30_OUT
2 13:09_IN_1
3 13:04_IN_1
Name: IN_1, dtype: object
Or using idxmax with reversed order of columns
df.ffill(axis=1).iloc[:, -1]+'_'+df[df.columns[::-1]].notnull().idxmax(1)
Out[375]:
0 13:05_IN_1
1 12:30_OUT
2 13:09_IN_1
3 13:04_IN_1
dtype: object

gnuplot shows actual data (time) in plotting

i have a series of data to plot. it ranges weekly. this is huge data so i just trimmed some of it
data:
2018-11-01 02:00, 3.04, 9.10
2018-11-01 02:15, 3.56, 0.00
2018-11-01 02:30, 50.67, 0.00
2018-11-01 02:45, 50.67, 0.00
2018-11-01 03:00, 50.68, 0.00
2018-11-01 03:15, 50.68, 0.00
2018-11-01 03:30, 50.68, 0.00
2018-11-01 03:45, 50.70, 0.00
2018-11-01 04:00, 50.73, 0.00
2018-11-02 02:00, 2.97, 9.10
2018-11-02 02:15, 12.27, 0.00
2018-11-02 02:30, 44.29, 0.00
2018-11-02 02:45, 47.39, 0.00
2018-11-02 03:00, 47.44, 0.00
2018-11-02 03:15, 53.03, 0.00
2018-11-02 03:30, 54.75, 0.00
2018-11-02 03:45, 54.88, 0.00
2018-11-02 04:00, 66.90, 0.06
2018-11-03 02:00, 2.81, 9.06
2018-11-03 02:15, 12.13, 0.00
2018-11-03 02:30, 34.95, 0.00
2018-11-03 02:45, 34.96, 0.00
2018-11-03 03:00, 34.97, 0.00
2018-11-03 03:15, 34.98, 0.00
2018-11-03 03:30, 34.98, 0.00
2018-11-03 03:45, 34.99, 0.00
2018-11-03 04:00, 34.99, 0.00
2018-11-04 02:00, 47.48, 0.00
2018-11-04 02:15, 47.48, 0.00
2018-11-04 02:30, 47.48, 0.00
2018-11-04 02:45, 47.48, 0.00
2018-11-04 03:00, 47.47, 0.00
2018-11-04 03:15, 47.47, 0.00
2018-11-04 03:30, 47.47, 0.00
2018-11-04 03:45, 47.47, 0.00
2018-11-04 04:00, 47.47, 0.00
is it possible to show actual time in every plot? that
should show the time under 2nd column of my sample data.
here's my code:
APPNAME=$1
START=$2
END=$3
FILE=$4
gnuplot -persist <<-EOFMarker
set grid
set terminal png font 'helvetica,11.5' size 850,550
set output '$APPNAME.$START.$END.png'
set title '$APPNAME $START.$END'
set ylabel 'Percentage Usage'
set yrange [0:100]
set xlabel 'Client Time'
set xdata time
set timefmt "%Y-%m-%d"
set xrange ["$START":"$END"]
set format x "%m/%d"
set timefmt "%Y-%m-%d %H:%M"
set datafile separator ","
set x2label "Memory = 60159 mb, SWAP = 4096 mb, Processor Count = 8" ##change this if you will use for other application
unset label
set key top center box width 1 height 1 opaque
set style line 1 lt 1 lw 3 pt 3 linecolor rgb "red"
plot '$FILE' u 1:2 w lp t 'Memory', '$FILE' u 1:3 w lp t 'Swap'
EOFMarker
Thanks in advance.
Not sure, if I understand you correctly. If you have data over several days it might be getting tight to additionally display the time.
But can be done:
exchange the line set format x "%m/%d" to set format x "%m/%d\n%H:%M", which will also display the time in a second line. But I guess there is probably not enough space to display much more xtics than 00:00 and 12:00.

How to start with negative axis polarplot using gnuplot?

From How to get a radial(polar) plot using gnu plot?
My data:
theta dB
0 0.00
30 0.09
60 -0.26
90 -0.26
120 -0.35
150 -0.35
180 -0.35
210 -0.35
240 -0.26
270 -0.09
300 -0.26
330 0.00
360 0.00
Axis will not start at 0 but it start at -2 to 0. How can i fix this code?
The range in polar mode is controlled by set rrange:
set polar
set grid polar
set angles degree
set size ratio 1
unset border
unset xtics
unset ytics
set rrange [-2:0]
plot 'file.txt' with lines
Result with 4.6.3 is:

Resources