Gnuplot - change background color - linux

I used gnuplot to create a graph on linux. The script creates a svg file, but its background has black and white squares. How can I create a white and clear background? The script that I used is below :
set terminal svg enhanced size 1000 1000 fname "Times" fsize 36
set autoscale
set output "plot.svg"
set title "A simple plot of x^2 vs. x"
set xlabel "x"
set ylabel "y"
plot "./data.dat" using 1:2 title ""

Those black and white squares are inserted by your viewer program, and indicate that you actually have no background. To get a white background, use the background terminal option:
set terminal svg enhanced background rgb 'white'
If your gnuplot version doesn't yet support this option, you can place a full-canvas rectangle behind the plot
set object rectangle from screen 0,0 to screen 1,1 behind fillcolor rgb 'white' fillstyle solid noborder
...
plot x

Related

How to show values upon mouse hover in Gnuplot in SVG?

After noticing the interactive gnuplot graphic upon https://lwn.net/Articles/723818/ showing country names on a mouse hover, I am wondering how to simply show the values of the points in a plot.
For example I want to hover over the "daughter bar" in https://s.natalian.org/2020-08-24/mouse-hover.svg and see 60 clearly.
However right now it just shows co-ordinates IIUC. How do I fix this?
set term svg mouse standalone
reset
$heights << EOD
dad 181
mom 170
son 100
daughter 60
EOD
unset key
set boxwidth 0.5
set style fill solid
set yrange [0:*]
plot '$heights' using 2:xtic(1) with boxes
set output '/tmp/mouse-hover.svg'
replot
You are looking for hypertext, check help hypertext.
You have to use point to anchor the hypertext.
Play with the pointsize (here ps 3) to change the area where the mouse will display the hypertext.
Since you probably don't want to display a colored point at the top of your box, make the color transparent, e.g. lc rgb 0xff123456.
Unfortunately, I haven't found (yet) anything in the gnuplot documentation how to make the font of this hypertext larger. The option font ",30" does not have any effect. If you find out please let me know. Apparently in wxt terminal you can do it (see gnuplot: Hypertext with monospace?).
Code:
### SVG standalone with hypertext
reset session
set term svg mouse standalone enhanced
set output 'tbSVGstandalone.svg'
$heights <<EOD
dad 181
mom 170
son 100
daughter 60
EOD
unset key
set boxwidth 0.5
set style fill solid
set yrange [0:*]
plot '$heights' u 2:xtic(1) w boxes,\
'' u 0:2:2 w labels hypertext point pt 7 ps 3 lc rgb 0xff123456
set output
### end of code
Result: (screenshot of SVG in Firefox. It looks like I can't place a SVG here, at least I don't know how.)

gnuplot svg blank space when output to PowerPoint

I have a gnuplot SVG terminal. One issue that I'm facing when I output the files and import to powerpoint is that there is a lot of blank space especially at the Top, even though I mention that margin is 0.
Below is the example and the screen shot that shows blankspace when imported in powerpoint.
My question is how to remove blank space so I dont have to trimp or crop using another tool.
reset session
set terminal svg size 600,600 enhanced font 'Verdana,10'
set output 'output.svg'
set view 50,10
set isosample 40
set xlabel "x"
set ylabel "y"
set zlabel "f(x,y)" rotate
set pm3d noborder
set palette rgb 33,13,10
unset colorbox
set lmargin 0
set rmargin 0
set bmargin 0
set tmargin 0
set log cb
set cbrange [0.1 : *]
splot [x=-2:2] [y=-1:3] (1-x)**2+100*(y-x**2)**2 with pm3d notitle
set output
The "set margin" commands in the form you show them are designed to describe the space between the x and y borders of a 2D plot and the edges of the page. Their effect on a 3D plot rotated so that the x/y plot borders are not parallel to the page is non-obvious.
I suggest using instead a different form of the bmargin command that positions the bottom of the 3D view box at a specific screen location, followed by a scaling command to increase the vertical size by a factor of, say 1.6 or so. The vertical scale operates symmetrically above and below the center of the 3D view box. My preference would be to also get rid of the empty space inside the view box by repositioning the base plane to z=0. The additional command and their result is shown here.
set bmargin at screen 0.4 # reposition entire plot upwards
set view 50, 10, 1.0, 1.6 # increase default vertical scale by 1.6
set xyplane at 0 # remove space between base plane and bottom of surface
replot

How to apply beatiful fading edge occlusion on Gnuplot's splot function?

Hello fellow stackers,
So I am a gnuplot afficcionado and I keep trying to use gnuplot to draw all sorts of things (including molecules) using it. These days I decided that it would be awesome if I could draw polyhedran in it with this beautiful thining-edge occlusion effect that we see in the interactive javascript polyhedral images here. See how the backside of the polyhedron is drawn differently from the front side and how they change dynamically as you rotate the solid? How can I do that in gnuplot?
I agree that is a really nice representation. Gnuplot cannot currently do the equivalent of "draw the inside edges using thinner lines", but the combination of partial transparency and using the background color as the fill color for the faces creates almost the same effect.
# Generation of polyhedral vertices and faces not shown.
# Each face is an object of type polygon, e.g.
# set object 1 polygon from ... to ... to ...
# make all the faces semi-transparent
set for [i=1:20] object i fillstyle transparent solid 0.6 fillcolor bgnd border lw 2
# use pm3d depthorder sorting to render the objects
# NB: gnuplot version 5.3 required
set for [i=1:20] object i polygon depthorder
set xrange [-2:2]; set yrange [-2:2]; set zrange [-2:2]
set view equal xyz
set view 30,30,1.5
unset border
unset tics
unset key
unset label
splot NaN
Results shown below for a cube and for an icosahedron. You can rotate them interactively as with any other splot.

histogram using gnuplot for multiple data in the same graph

I am trying to plot two data series plotted in one graph (histogram) using gnuplot. One is Baseline data and other one is Optimized. The script looks like this currently.
n=50
max=0.07946462
min=0.0
reset
width=(max-min)/n #interval width
hist(x,width)=width*floor(x/width)+width/2.0 #function used to map a value
to the intervals
set term png #output terminal and file
set output "histogram.png"
set xrange [min:max]
set yrange [0:]
set style fill solid 0.5 #fillstyle
set termopt enhanced # turn on enhanced text mode
set xlabel "PowerDensity(mA/um2)"
set ylabel "Area(um2)"
set title 'Power Density Histogram'
plot 'power_density_oxili_sptp.txt' u (hist($2,width)):($1) smooth frequency
w boxes lc rgb"blue" title 'Baseline', 'power_density_oxili_sptp.txt' u
(hist($3,width)):($1) smooth frequency w boxes lc rgb"red" title 'Optimized'
The output of this will be as given
enter image description here
The problem here, I am not able to see baseline data (blue) completely,since it is hiding below the optimized data.Either I need to see both data or I need to plot histogram separately in the same graph.
Br
Sree
It looks like you want the two histograms to be transparent. For that you should set the transparent flag in your fillstyle (see help fillstyple):
set style fill transparent solid 0.5
In addition, you need to specify truecolor to get transparent areas from the standard png terminal (see help png):
set term png truecolor
Alternatively you can use the pngcairo terminal.

Gnuplot png file without border line

I want a gnuplot png file to seamlessly blend into the background page color of a website. Setting a background rectangle for the plot with a specific rgb color spec and the same rgbfor the html page works fine.
Colored gnuplot rectangle:
set object 1 rectangle from screen 0,0 to screen 1,1 behind fc rgb "#d0d0e0" lw 0
HTML page background color:
<body text="#000000" bgcolor="#D0D0E0" link="#0000EE" vlink="#551A8B" alink="#FF0000">
Now I would like to get rid of the fine black line around the plot (not the axis, the line around the border) so that it blends into the background perfectly.
I have tried lw 0 as above or setting rectangle styles with noborder or border -1 but none works. I should mention that this is on gnuplot 4.6 patchlevel 0.
You can see the problem on my page here:
http://drgert.dyndns.ws:8000/bmp085/bmp085.php
Thanks for helping,
Gert
Option 1
The simplest option may be to avoid making a background rectangle and instead create a transparent .png:
set term png transparent
set output 'foo.png'
plot x
That way, the image will blend into the page regardless of background color.
Option 2
If you do want the rectangle without a border, then use set style rectangle:
set style rectangle fillstyle noborder
Using this option, you may get a one-pixel white/transparent border at the edge of your .png. To get around this you can make the rectangle bigger than the screen:
set object 1 rectangle from scr -0.1,-0.1 to scr 1.1,1.1 behind fc rgb "#d0d0d0"
Note that this works only with screen coordinates; otherwise the rectangle will be clipped to fit into the plot border.

Resources