Gnuplot misscalculating functions - math

Im trying to get Gnuplot to plot the function arctan(0.0199/(0.000415+x)).
My code is
f(x)=atan(0.0199/(0.000415+x))
plot f(x) title "stuff",
bur for some reason Gnuplot seems to be interpreting the part inside the brackets as a factor, visible in the fact that the arctan doesen't reach the expected maximum of pi/2. I have added the final below.
The aformentioned Plot.

gnuplot is old! back in the day, monitor resolutions were much smaller. So, the default sampling rate was chosen to be 100. This means, whatever your xrange is, gnuplot will sample 100 points evenly distributed in your xrange. Many maxima and minima are missed because of this.
However, as #user8153 points out, set samples 10000 to the rescue. gnuplot will now sample 10,000 x values in your xrange. 10000 is a good number but smaller will do. Experiment, at 5000, it looks like the function reached pi/2. At 1000 you can see it does not make it.
set yrange [0:2]
set samples 10000
f(x)=atan(0.0199/(0.000415+x))
plot f(x) title "stuff"
replot pi/2

Related

continues density plot seaborn with lower limit

I have been using this code for my continues parameters to plot the probability distributions. However, my parameter now is price that cant be below zero, I have been reading to see if I can customize the density function so it dsnt go into negative numbers but havnt really found an answer. Does anyone know if there is a way to bound the density function?
fig = plt.figure(figsize=(6,4))
sns.distplot(data2018[ 'price'], hist=False)
sns.distplot(data2020[ 'price'], hist=False)
fig.legend(labels=['2018','2020'], bbox_to_anchor=(0.9,0.85))

Auto-Scaling Scatter Plot Axis Based on Input Data

I am writing a module that creates a scatter plot from a 2 dimensional array of numbers provided by the user (x and y values). It is intended that the graph axis will be scaled to the value required to encompass all the input numbers, while also rounding to an aesthetically pleasing value. For example, if the maximum value entered is 4.56, I would like it to round the maximum axis value to 5. If the maximum value is 850, I'd like it to round the axis to 1000.
This initially seems like a simple task. Simply take the max value and round up. However, what makes it difficult is my module could be dealing with input values as small as 0.00000001 or as large as many billions.
Can anyone suggest a workflow for making this happen? I don't need the code itself, just the process required. The only way I have come up with is an extremely cumbersome iterative approach that still handles unusual values rather poorly.
Any advice would be most appreciated!
Thanks,
Greg

Population Pyramid in Plotrix freezes r [duplicate]

I am trying make a pyramid plot with R. The I found a example code in the internet that does what I want. The problem is that I am not working with small numbers as in the example. My plot has values of 3,000,000 to 12,000,000 but only 10 bars per side. Never the less it takes for ever create the plot with the larger numbers and output pdf file is about 800mb of size.
pyramid.plot(x,y,labels=groups,main="Performance",lxcol=mcol,rxcol=fcol,gap=0.5,show.values=TRUE)
Why is the performance so bad? Shouldn't get scaled automatically?
Update:
pdf(file='figure1.pdf')
library(plotrix)
x <-c(3105000,3400001,4168780,2842764,3543116,4224601,4222222,6432105,9222222,12345596)
y <-c(3105000,3400001,4168780,2842764,3543116,4224601,4222222,6432105,9222222,12345596)
groups <-c("g1","g2","g3","g4","g5","g6","g7","g8","g9","g11")
pyramid.plot(x,y,labels=groups,main="Performance",gap=0.5,show.values=TRUE)
dev.off()
Both the export to pdf as well as the plotting screen takes multiple minutes.
Internally, pyramid.plot is trying to do some stuff to finagle the axes accounting for the gap in the middle: if you do debug(pyramid.plot) and step through line-by-line you find where the problem is:
if (is.null(laxlab)) {
laxlab <- seq(xlim[1] - gap, 0, by = -1)
axis(1, at = -xlim[1]:-gap, labels = laxlab)
}
in other words, pyramid.plot is trying to make an axis with ticks every 1 (!) unit.
Something like this works OK:
pyramid.plot(x,y,labels=groups,
main="Performance",gap=5e5,show.values=TRUE,
laxlab=seq(0,1e7,by=1e6),raxlab=seq(0,1e7,by=1e6))
there are a few other vestiges of the fact that pyramid.plot was designed for demographic plots ... you might write to the package maintainer and ask him to think about generalizing the design of the axes a little bit ...

Gnuplot: How to remove vectors below a certain magnitude from vector field?

I have a 2D CFD code that gives me the x and y flow velocity at every point on a grid. I am currently visualizing the data using a vector field in gnuplot. My goal is to see how far the plume from an eruption extends, so it would be much cleaner if I could prevent vectors from showing up at all in the field if they fall below a certain magnitude. Does anyone have an idea how to go about this? My current gnuplot script is below. I can also modify the input file as necessary.
reset
set nokey
set term png
set xrange [0:5.1]
set yrange [0:10.1]
do for [i=0:10] {
set title 'Eruption simulation: Timestep '.i
set output 'path/FlowVel'.sprintf('%04.0f',i).'.png'
plot 'path/Flow'.sprintf('%04.0f',i).'.dat' using 1:2:3:4 with vec
}
I guess you want a kind of filtering, which gnuplot doesn't really have, but can be achieved with the following trick (taken from "help using examples" in gnuplot):
One trick is to use the ternary `?:` operator to filter data:
plot 'file' using 1:($3>10 ? $2 : 1/0)
which plots the datum in column two against that in column one provided
the datum in column three exceeds ten. `1/0` is undefined; `gnuplot`
quietly ignores undefined points, so unsuitable points are suppressed.
Or you can use the pre-defined variable NaN to achieve the same result.
So I guess you would want something like this in your case
plot "data.dat" u 1:2:($3**2+$4**2>mag_sq?$3:NaN):($3**2+$4**2>mag_sq?$4:NaN) w vector
where mag_sq is the square of your desired magnitude.

Gnuplot: point size units

How can I set the point size in gnuplot in the units of the plot coordinates?
In other words, the points should get smaller if I increase xrange.
It looks like this is all terminal dependent. Is there a workaround?
Here's a small example using inline data ...
plot '-' u 1:2:1 ps variable
1 2
2 3
3 4
4 5
5 6
e
Note that while it is possible to change the pointsize using a column from your datafile, I am not aware of any way to specify how large each point should be since the pointsize (and even the pointtype) is a terminal dependent quantity. The only workaround that I can come up with is to scale the points by a terminal dependent value.
default_value=1.0
func(x)=1.0*x #Change this to change the functional dependence of the pointsize on x.
scale_point(x)=(GPVAL_TERM=="postscript") ? 1.0*func(x) :\
(GPVAL_TERM=="png") ? 2.0*(x) :\
default_value
plot "mydata.dat" u 1:2:(scale_point($1)) w pt ps variable
It's ugly, but it should get the job done -- You could also write a similar function which returns the pointtype to achieve some sort of terminal independence with that as well...
EDIT
Note, my points increase in size linearly as x gets bigger, but you can substitute any function you want to make the points get smaller as you see fit.
What I am saying is that I don't believe that option exists since as you state "all this is terminal dependent". I tried to provide a ugly hack to allow you to modify this on a per-plot basis with minimal intervention -- allowing for different terminals, etc.
EDIT 2
While responding to your comment, I remembered an odd little corner of the gnuplot documentation that may be helpful.
set style fill transparent solid noborder #whatever fillstyle you want...
plot 'mydata' u 1:2:3 w circles
see help circles ... I'm not sure when this feature was introduced, probably with gnuplot 4.3, but if you're using 4.2 then give it a try and let me know how it goes...
If I understand the question correctly, you just want the pointsize to be a decreasing function of the xrange. Exactly how big the points are printed and what they look like does depend on the terminal. But it's not hard to get the basic behavior that you want.
First, define a function to return the pointsize. Let's try
sps(a,b) = 1./(b-a)
Set your xrange:
set xrange [0:3]
Make a plot that you won't use:
plot sin(X)
We did that in order to get some of gnuplot's special variables defined. Now we can do
plot sin(x) with points pt 7 ps sps(GPVAL_X_MIN, GPVAL_X_MAX)
If you now reset the xrange and re-enter both plot commands, you will see that the pointsize changes, inversely proportional to the xrange. You probably want a different function for pointsize than the "sps" example that I used. I hope this is something like what you were after.

Resources