Gnuplot 3d plotting --- making plot size set to terminal size - plot

Okay I have been working with gnuplot for sometime and have one question. I cannot make the plot size equal to the terminal size I set it to. There are examples of setting
Lmargin,rmargin, tmargin and bmargin to 0 but this doesn't work on 'splot' which is 3d plotting. So I want to know what is the workaround for it?

For color maps you can use plot ... with image instead of set pm3d map if you want to use the margin options as usual. For 3d plots, as you say, the margin options are not available, and a workaround would be to shift the position of your graph and scale it. To do that, use set origin and set size respectively.
For instance, splot x*y yields the following:
If you want to reduce the margins while keeping the same overall terminal size, you can try:
set origin -0.1,-0.1
set size 1.2,1.2
splot x*y
which gives you:
You probably get the idea. Note I set a background color just so you can visualize where the margins lie because of the white background in the Stack Overflow website.

Related

How to expand your plot so all labels can be seen without overlapping in R

I have a plot with 50 categories(states) that show on my X axis, but in my output they are on top of each other. I want my plot to be spread out engough/large enough that there is no overlap and you could determine the state value from the next.
NOTE: i used the coord_flip command, so I know that my X-axis is actually my Y in image and vice versa. I am just wondering what function I would use to fix problem.
You can always change the size of the text via themes(axis.text.x=element_text(size=...))...
But the easy answer here is that your plot will change appearance based on the aspect ratio. When you view in Rstudio, you can adjust the size of your plot and you'll see the rearrangement. Additionally, when you save, the plot, play around in particular to the height and width to get the ratio you want. ggsave('filename.png', width=??, height=??).

gnuplot: floating terminal width ? fixed terminal height

Can you tell us how to make the chart with all headings and captions fit into the fixed vertical size and the horizontal size is floating?
If I set small fixed image sizes, some axes captions disappear, and if I set large fixed image sizes, then there is an empty space on the sides.
And I want you to be able to specify the height of the image and gnuplot will determine for itself what its width must be to fit everything you need.
For example (margin - empty space, but on the right, the inscription didn't fit:
set terminal pngcairo notransparent enhanced font "Calibri, 15" fontscale 1.0 size 800, 800; set zeroaxis;
Apparently, gnuplot does not automatically provide enough space for long numbers in the colorbox.
Since you have a logarithmic scale from 0.0000001 to 0.1, you might want to consider to display your numbers in a different format, i.e. from 10^-7 to 10^-1.
Code:
### no long numbers in colorbox
reset session
set colorbox
set palette rgb 33,13,10
set xrange [-7:-1]
set cbrange [1e-7:0.1]
set logscale cb
set format cb "10^{%T}"
plot '+' u 1:1:(10**$1) w l lw 3 palette z notitle
### end of code
Result:

Save Filled Area of Polygon in R

I am plotting polygon in R and saving it.Problem, I am facing is that the whole plot is saved as png file but I want to save only the filled area in the polygon.
Is there a way for that ?
x<-c(0.000000000,0.010986328,0.006351471,-0.004634857)
y<-c(0.000000000,0.007232612,0.012841203,0.006199415)
file_name = paste("~/Downloads/Plot", ".png", sep="")
png(file_name,width=1280,height = 720,units="px",res=200)
plot(x,y,axes=FALSE,ylab='',xlab='')+polygon(x,y,col="#FF0000FF")
dev.off()
If you're drawing a monofigure plot (which is the default), then I believe there are three possible sources of spacing that can cause a plot element to not extend to the edges of the graphics device:
1: data coordinate limits that are larger than the extent of the plot element.
2: "internal spacing", which is best thought of as an expansion of the plot area that sits inside the margins.
3: margins. This is normally where axes, ticks, tick labels, axis labels, titles, and sometimes legends are drawn.
All of these sources of spacing can be eliminated with the following customizations:
1: set the xlim and ylim graphics parameters to perfectly fit the target plot element.
2: set xaxs='i',yaxs='i', which can be done with either a preemptive par() call or on the initial plot() call.
3: zero the margins with mar=c(0,0,0,0). This must be done with par() prior to the initial plot() call.
Example:
## generate data
pts <- data.frame(x=c(0.2,0.4,0.9,0.7),y=c(0.5,0.4,0.5,0.6));
## precompute plot parameters
xlim <- range(pts$x);
ylim <- range(pts$y);
## draw plot
par(mar=c(0,0,0,0));
plot(NA,xlim=xlim,ylim=ylim,xaxs='i',yaxs='i',axes=F,ann=F);
points(pts$x,pts$y,pch=21L);
polygon(pts$x,pts$y,col='red',pch=21L);
Multifigure plots can incur one additional source of spacing, namely outer margins, but it looks like that doesn't concern you for this problem. In any case, I'm pretty sure outer margins always default to zero anyway.
See par() for the relevant documentation.
It looks like I misunderstood the question. What you want is a transparent background, which is different from simply fitting the image size to the plot element.
You can use the png() function to set the background to be transparent by passing bg='transparent', as explained on the documentation page.
For example, here's my fitted image saved with a transparent background:
Note that not all image viewers will correctly detect and/or clearly depict the transparency of the background. I would highly recommend GIMP, which is basically a free Photoshop knockoff, albeit markedly lighter in features. GIMP depicts transparent regions as a kind of checkerboard of grey squares, which looks like this:

change the font size and margin of R graph

I am experimenting with the investigate_var_importance in package of bartMachine
investigate_var_importance(bart_machine_cv, num_replicates_for_avg = 20)
It turns out that the generated graph is so big, especially the text label along with the x-axis. The default [R Graphics: Device 2(Active) cannot even hold the whole picture. How to change the font size and margin of this plot?
margin can be set by par(mar=c(bottomMargin, left, up, right))
see par to set that parameter
c(0,0,0,0) will not leave any space. You might not want this, as there wouldn't be any space for the axis.
par(oma=c(bottomMargin, left, up, right))
sets the outer margins of the plot
if you send the plot to a pdf, you can increase the size of the plot, which will be able to hold the whole plot i.e,
pdf('nameOfplot.pdf', 20, 6) ## opens a device, and produces a file much wider than longer
plot whater you want
dev.off() ## closes the device you have opened with pdf
if you play with those parameters you might be able to fit your plot

gnuplot: how to set plotting area to be a pixel perfect representation of data

I'm having difficulty getting GNUplot to properly render some of my data. Basically I have some 2D heightmap data (for example 512 x 128 data points) and would like to be able to plot this in a "pixel perfect" fashion (i.e. one pixel per data point). Unfortunately at the moment, I'm getting artefacts (see inset) due to the number of pixels being slightly larger than the number of data points. I know I can set the total size of the output using:
set terminal png size 800,400
but is there a way to set just the plot area size in pixels?
Thanks!
From the help of the lua/TikZ terminal (there is an option plotsize) it is suggested to remove the plot margins so that plot fills the whole canvas.
set lmargin 0
set rmargin 0
set tmargin 0
set bmargin 0
set terminal png size 512,128
set out 'out.png'
# a checkerboard pattern to test the plot results for errors
f(x,y)=( (x<=0) || (x>=63) || (y<=0) || (y>=63) ) ? 0.5 : ((x+y)%2==0)?0:1
# the 'map' file contains only coordinates.
plot[-1:63][0:64] 'map' u 1:2:(f($1,$2)) with image
unset out
However, this has the drawbacks that you will not have tic labels and so on. You can of course calculate values for the margins yourself, so that they match with the plot size in the end: use
set lmargin at screen 0.25
for example.
Anyway, I would also recommend going for vector graphics whenever possible.

Resources