Gnuplot Density Mapping: Tips and Tricks for Efficient Data Plotting

Click For Summary

Discussion Overview

The discussion revolves around using Gnuplot for density mapping of data files, specifically addressing issues related to formatting data for 3D density plots. Participants explore methods to efficiently process large datasets to meet Gnuplot's requirements for blank lines separating different x values.

Discussion Character

  • Technical explanation
  • Exploratory

Main Points Raised

  • One participant shares a bash script for plotting data with Gnuplot but encounters a warning about insufficient isolines for a pm3d plot, suggesting that blank lines are needed to separate different x values.
  • Another participant suggests running a script to remove multiple carriage return-line feed (CR-LF) instances to streamline the data formatting process.
  • A participant unfamiliar with Gnuplot asks for clarification on how to implement the suggested solution for removing extra CR-LF values.
  • Further clarification is provided that the solution is not Gnuplot-specific and can be implemented in various programming languages, emphasizing the need to read lines from the file and filter out blank lines.

Areas of Agreement / Disagreement

Participants do not reach a consensus on a specific solution, as the discussion includes various approaches to handling the data formatting issue without resolving which method is optimal.

Contextual Notes

The discussion highlights the need for specific formatting in Gnuplot and the challenges of processing large datasets, but does not resolve the technical details of the proposed solutions.

s_hy
Messages
57
Reaction score
0
Hi all,

I used below bash command to plot my data (.dat file)

Code:
#!/bin/bash

(
echo 'set term jpeg'
echo 'set style data lines'
echo 'set yrange [0:200]'
echo 'set xrange[0:200]' 
echo 'set pm3d map'
echo 'set palette defined (-2 "yellow", 0 "green", 2 "red")'for f in "$@"
do
#	echo "Processing $f" >&2
	pic_name="${f%.dat}.jpg"
	echo "set out '$pic_name'"
	echo "splot '$f'"
done) | gnuplot

but I got this warning:

Warning: Single isoline (scan) is not enough for a pm3d plot.
Hint: Missing blank lines in the data file? See 'help pm3d' and FAQ.

As I know, to map using gnuplot for 3d density mapping, I should have output with blank lines to separate different x values, like this

Code:
-180.0 -180.0 0.0
-180.0 -179.0 0.2
[...]
-180.0  180.0 0.0

-179.0 -180.0 0.4
-179.0 -179.0 0.2
[...]
-179.0  180.0 0.0

[...]

but, if I have a few thousand lines, with 200 .dat files, what can I do to expedite my job? Anyone can help...thank you in advance.
 
Last edited:
Technology news on Phys.org
Hey s_hy and welcome to the forums.

One idea I have for you is to run a script (or write some code to create an executable) to just remove every instance of a double or more than double CR-LF (carriage return line-feed) and just set it to a single CR-LF.
 
chiro,

how can I do that? gnuplot is new to me..still not familiar with the command
 
It's not a gnuplot specific suggestion: it's a general one that can be implemented on your language (scripting/non-script/whatever) and platform of your choice.

All you want to do is basically read in every line of the file that is relevant and whenever you encounter a file with multiple CR-LF (carriage return-line feed) values just remove all of them but one.

If you want to know what these values are use a hex-editor and look at the raw data and see if it's just a one or two byte code and you'll see what the values are.

The simplest way to do this without even worring about the CR-LF values is to just have a loop that reads in one line at a time and then if the line is blank forget about it and if not write it to another file.

When the loop terminates you'll have another file without any extra spaces in the data and you can use that.

It's basically just an open statement, one loop that reads until end of file, read line, check if empty or with only spaces and if so don't add it to output but if not write that line to the output file, loop terminates, close input file, flush output to existing file close handle, program exits and you have a file that has no gaps.

If you have any platform that allows you to read in one line at a time and write one line at a time you're looking at something like 10-20 lines for the entire thing and will do its magic pretty much on the spot.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
5K
Replies
4
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
7K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 14 ·
Replies
14
Views
11K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 2 ·
Replies
2
Views
5K
  • · Replies 1 ·
Replies
1
Views
2K