How to prevent labels to overlap - gnuplot

I am running the following command to draw a few X,Y points in gnuplot:
plot "Output.tsv" using ($2+3):($3+3):1 with labels, "Output.tsv" using 2:3
Some of the data points are very close to each other and it makes the label unreadable. Is there a way to ask gnuplot to eliminate/reduce the overlap between labels?

I think you could consider 3 options:
1) make your graph huge and hope your labels do not overlap
2) plot the points as different series with each item having its own legend
3) use letters instead of labels, you can put a letter at each point using
plot "???" using 1:2
plot "" using 1:2:(stringcolumn(3) ne 'compare to' ? 'if equal' : 'if not equal' ) with labels
the stringcolumn function looks in column 3, compares the value to the string 'compareto' and if there is a match it puts 'if equal' at that location, otherwise 'if not equal'
Hence, I see something like Simulator in your graph, you could keep the green point and put an S with it/on it using
plot "" using 1:2:(stringcolumn(3) ne 'Simulator' ? 'S' : '' ) with labels
I hope this helps.

Related

Putting a value from an input data file into 'Set Label'

I'm plotting an animated surface in gnuplot and want to read in an average or sum of the mapped z values and include this in a label to be printed in the plot, so that I get a running total updated as the GIF progresses. It's probably straightforward, but I'm a "gnu"bie, so to speak, and find this system pretty confusing!
I've tried putting the running sum and average numbers in additional columns ...
splot 'output3.dat' index i:i using 1:2:(column(3), TD1 = strcol(4), TD2 = strcol(5)) with pm3d
but this doesn't plot, and the string variables TD1, TD2 don't seem to exist outside the splot command.
The command you show would indeed set variables TD1 and TD2 globally if you change the order of clauses in the serial evaluation expression (the comma-separated sub-expressions):
splot 'output3.dat' index i:i using 1:2:(TD1 = strcol(4), TD2 = strcol(5), column(3)) with pm3d
However, if the idea is to create a label using set label that will appear as part of the resulting graph, this won't work. The set label command would have to be executed before the splot command, so TD1 and TD2 will not have the correct values yet.
There is an alternative that might serve you better. Instead of trying to put this dynamically evaluate information in a label, put it in the plot title. Unlike a label, the plot title is evaluated after the corresponding plot is generated, so any variables set or updated by that plot will be current. [caveat: this is true for current gnuplot (version 5.4) but was not always true. If you have an older gnuplot version the title is evaluated before the plot rather than after].
Since current gnuplot also allows you to place the individual plot titles somewhere other than in the key proper, you have the same freedom that you would with a label to position the text anywhere on the output page. For example, if you want to sum the values in column 3 of the data file and print the total as part of a title above the resulting plot:
SUM = 0
splot 'foo.dat' using 1:2:(SUM = SUM+column(3), column(3)) with linespoints title 'foo.dat', \
keyentry title = sprintf("Points sum to %g", SUM) at screen 0.5 0.9
I used a separate keyentry clause because this allows to omit the sample line segment that would otherwise be generated, but it would also be possible to make this the title of the plot itself if you want that sample line.

Splot triangles from binary data file

I have a binary files that have binary format='%float32%float32%float32', having D3 points (using 1:2:3). Originally logically points grouped by 3 to form triangles. I want to plot just legs of triangles as a lines using with lines. In ASCII data file I can make so-called datablocks by adding an empty line between triples of lines, but in binary I can't. I want to break a chain of lines at every three points to form at least V-like parts of triangle contours.
Is there an option to make gnuplot to treat a triples of points as separate datablocks?
Is there another option to splot the data as (maybe) a solid triangles?
I'm still not sure whether I'm fully on the right track.
The following code writes your binary data into a table and makes groups of 3 datapoints for a triangle, inserting an empty line and then shifted by one for the next triangle.
So, So from the points p1=f1,f2,f3; p2=f4,f5,f6; p3=f7,f8,f9; ... it creates the triangles p1p2p3p1 p2p3p4p2 p3p4p5p3 (space=empty line).
Certainly, not very (memory) efficient, but maybe this gets closer to your final goal.
Check help pm3d and help hidden3d, where you might get some additional information.
I very much hope that there is a better approach.
Code: (assuming the binary file 'myBinary.bin', not sure whether I decoded your ASCII string correctly)
# plot binary data
reset session
# put binary data into a datablock
set table $Data
plot 'myBinary.bin' u 1:2:3 binary format='%float32%float32%float32' skip=12 w table
unset table
# separate each triangle by an empty line
set print $Data2
do for [i=1:|$Data|-2] {
print $Data[i]
print $Data[i+1]
print $Data[i+2]
print $Data[i]
print "" # insert empty line
}
set print
set pm3d hidden3d
set view 40, 24
splot $Data2 u 1:2:3 w pm3d notitle
### end of code
Result:

How to use df.plot to set different colors in one plot for one line?

I need to plot line plot that has different colors. I create special df column 'color' that contains for each point appropriate color.
I already found the solution here:
python/matplotlib - multicolor line
And take the approach from the above question. First, it was working when I use index but now I need to plot it vs other column and I can not appropriately handle the colors. It is all the time colores only with one color.
I use this code for setting colors, but it color line with one color that is the last in the column 'color'. And also create a legend that I don't understand how to delete from the plot.
for color2, start, end in gen_repeating(df2['color']):
print(start, end)
if start > 0: # make sure lines connect
start -= 1
idx = df2.index[start:end+1]
x2 = idx
y2 = df2.loc[idx, 'age_gps_data'].tolist()
df2.plot(x='river_km', y='age_gps_data', color=color2, ax=ax[1])
ax[1].xaxis.set_major_locator(plt.MaxNLocator(5))
plt.setp(ax[1].get_xticklabels())
I would appreciate any help.
How can I set these colors to achieve different color in one line? And don't have legend on the plot.

How to plot line from point to point in gnuplot?

how could I plot x axis (graph withnout y axis) with various color lines connectig intervals?
For example:
First line I want to go from point (1,8) to (6,8) - first color
The second: from (12,8) to (40,8) - second color
The third: form (50,8) to (56,8) and (60,8) to (74,8) - third color
I tried this as sorce file
56278.5545, 52676,5737
56300.5016, 55833,2969
and commands
plot 'pokryti.txt' using 1:0 with lines, '' using 2:0 with lines
but there is not constant for y value.
Or I tried to add trird column with sames values and
plot 'pokryti.txt' using 1:3 with lines, '' using 2:3 with lines
but nothing was plotted.
Thank you very much.

gnuplot setting line titles by variables

Iam trying to plot multiple data lines with their titles in the key based on the variable which I am using as the index:
plot for [i=0:10] 'filename' index i u 2:7 w lines lw 2 t ' = '/(0.5*i)
However, it cannot seem to do this for a fractional multiple of i. Is there a way around this other than to set the title for each line separately?
sprintf should provide all the functionality needed, e.g.,
plot for [i=0:10] .... t sprintf(" = %.1f", 0.5*i)
in order to use the value of 0.5*i with 1 decimal digit...

Resources