I found this very helpful post here on plotting a heat-map on a non-uniform grid: Heatmap with Gnuplot on a non-uniform grid
Now everything works great if I put the suggested commands manually in gnuplot. However, I want to automate the graph by writing a shell-script that I can call directly in my fortran code.
This is the script (Map_Ent.sh):
#!/bin/bash
gnuplot <<- EOF
set pm3d map corners2color c1
set autoscale fix
set ytics 1
splot 'Career_Choice.txt' using 1:($2-0.5):3
EOF
eog Ent_map.png &
And this is how I call it in Fortran:
call SYSTEM('bash ./Map_Ent.sh')
However my graph is completely white when I do it this way. Any ideas on what I am doing wrong? I would be very thankful for any suggestions!
The $2 is interpreted by bash and evaluates to nothing. Therefore, gnuplot plots only -0.5. $2 is a shortcut for column(2). Just use the latter and it should work fine:
#!/bin/bash
gnuplot <<- EOF
set pm3d map corners2color c1
set autoscale fix
set ytics 1
splot 'Career_Choice.txt' using 1:(column(2)-0.5):3
EOF
There is no need to use bash as intermediate step, just use a gnuplot script:
file.gp:
set pm3d map corners2color c1
set autoscale fix
set ytics 1
splot 'Career_Choice.txt' using 1:(column(2)-0.5):3
And then
call SYSTEM('gnuplot -persist file.gp')
(I'm not sure about the fortran call, just copied from the question).
Related
My goal is to be able to colorize (or set underlining, etc) terminal window output from any source (I figure if ls works, all the rest will too) on an as-needed / as-desired basis via command line scripts. ...It's a given here that SOME programs may very well override this in their output, and insofar as that's an easy to address aspect of this question, that's in there, too - as in, I'd sort of like to know how that may pertain to any answer(s).
I already understand a heck of a lot of the background information as I use color in my shell scripts now. The issue is they don't persist when their shell exits; my focus in this question is on making functional a set of a few command line utilities that can let the user select from a set of known named colors, like Blue or Red, or even just give the correct code to do that, and leave all output to that terminal window in that situation until a reset is given, via a command line script, though surely if another command utility, like 'reset' were to reset it, so be it!
I believe this is likely possible through use of what for me at least are rarely touched elements of the environment like PS1.
I've touched that stuff so rarely, I really don't know what I'm doing there!
On Linux, if you are using a scrolled terminal that responds to the SGR standard, colours instructions sent to that display stream will remain (persist) until you flush that display stream with the "clear" command.
The execution of the below script will illustrate that with one set of FG/BG colours, then the terminal defaults, then another set of FG/BG colours:
#!/bin/sh
### Useful References:
### https://www.ecma-international.org/publications-and-standards/standards/ecma-48/
### https://en.wikipedia.org/wiki/ANSI_escape_code
###
### https://www.htmlcsscolor.com/hex/FFFF80
### https://www.w3schools.com/colors/colors_picker.asp?colorhex=FFFF00
### https://www.colorabout.com/color/hex/ffff80/
### https://www.color-name.com/hex/ffff80
### https://www.cpcwiki.eu/index.php/CPC_Palette
### https://hexcolor.co/hex/ffff80
### https://www.colorxs.com/color/hex-ffff80
### https://encycolorpedia.com/ffff80
### https://www.color-hex.com/color/ffff80
### https://www.colorcodehex.com/ffff80.html
### http://html-color.org/FFFF80
cat >sample_text.txt <<"EnDoFiNpUt"
The original specification only had 8 colors, and just gave them names. The SGR parameters 30–37 selected the foreground color, while 40–47 selected the background. Quite a few terminals implemented "bold" (SGR code 1) as a brighter color rather than a different font, thus providing 8 additional foreground colors. Usually you could not get these as background colors, though sometimes inverse video (SGR code 7) would allow that.
EnDoFiNpUt
FG_color="\e[91m" ### Red
BG_color="\e[47m" ### Gray
echo "${FG_color}${BG_color}"
cat sample_text.txt
echo "\e[0m" ### Environment Default
cat sample_text.txt
FG_color="\e[30m" ### Black
BG_color="\e[102m" ### Green
echo "${FG_color}${BG_color}"
cat sample_text.txt
echo "\e[0m"
That will appear as follows (on my terminal):
I can't run my gnuplot script in background within a shell script. Something like in following example
#!/bin/bash
for i in 1 2 3
do
run gnu_script($i).p
done
As per the answer given by Christoph I could able to do it. But still the figure windows are coming and not letting me to do anything in the computer.
What about something simple as
for i in 1 2 3
do
gnuplot script$i.gp &
done
That assumes, that you have different scripts script1.gp, script2.gp and script3.gp.
If you have only a single script and want to pass the iteration number to it, you could do it with
for i in 1 2 3
do
gnuplot -e "i=${i}" script.gp &
done
A simple gnuplot script script.gp for testing this is
set terminal pngcairo
set output sprintf('script%d.png', i)
plot x title sprintf('%d', i)
pause 10
The pause 10 makes gnuplot pause for 10 seconds.
Currently, I do something like the following:
set term png
set output 'file.png'
But hardcoding filename in the script is quite inflexible. Is there some way to tell gnuplot to output image file to stdout, so I will be able to redirect it's output where needed?
If you do want to send your .png to stdout, just don't set the output:
#!/usr/bin/env gnuplot
set term png
plot x
Then run the script
./plot.plt > mypng.png
I think the bash wrapper makes more sense for most purposes, but this is potentially useful as well.
Put your gnuplot script inside a script and use a here document:
#!/bin/bash
gnuplot << EOF
set term png
set output "$1.png"
plot "$1.dat"
EOF
Now invoke the script, say plot.sh, by specifying the prefix to output file and data as argument: bash plot.sh file.
I'm trying to show an animation using gnuplot
I got the following script:
plot ”heat1d.txt ” using 1:2 every :::a::a
pause 0.01
a=a+1
if ( a<b ) reread
that I execute using
a = 0
b = 100
load "a.plot"
it works, but is there a way to execute all of this using only 1 command from a shell?
Alternatively is there a way to integrate the variable definitions into the .plot file so that I can simply execute it? I tried different things like echo 'a=0'|gnuplot etc but it doesn't seem to actually define the variable correctly
thanks
You can use a do for loop.
do for [a = 0:100] {
plot ”heat1d.txt ” using 1:2 every :::a::a
pause 0.01
}
The default terminal on linux is usually wxt, and it has the raise option, which will change the focus to the plot window at every iteration. This will make it difficult if not impossible to stop the animation.
I suggest to put noraise as the terminal option. For example, you can put the following line at the beginning of the script:
set term wxt noraise
Now, if you want to stop the animation halfway, press CtrlC on the gnuplot terminal.
You can pass -e as a commandline argument. For example, if you have the script:
#script test.gp
print foo,bar
Then you could run it with gnuplot using:
gnuplot -e "foo=1;bar=2" test.gp
In your case, it looks like you could accomplish nearly what you want by invoking your script as:
gnuplot -e "a=0;b=100" a.plot
I have to plot a graph using gnuplot with the help of shell script.
I have written this code but its not working. I want to plot the graph in a html file so that I can see that graph in browser.
echo "set term canvas mousing size 500, 500
set output "file_name.html"
plot 'my_file.txt' with lines" | gnuplot
I have saved this file in .bash on the desktop.
Now I wrote this in terminal but it didn't work
sh file_name.bash
Please someone help me out with this. I am totally stuck with this thing since yesterday. :-(
There are multiple errors,
you use double-quotes within the echo which will not work. change it to single-quotes
use semi-colon instead of a line break for multiple gnuplot commands
So resulting script should be something like this
echo "set term canvas mousing size 500, 500; set output 'file_name.html'; plot 'my_file.txt' with lines" | gnuplot
or
cat << __EOF | gnuplot
set term canvas mousing size 500, 500
set output "file_name.html"
plot 'my_file.txt' with lines
__EOF