Quantization distortion in x-axis of GLMakie plot. Why? - julia

I create a simple plot using GLMakie:
GLMakie.scatter( range((-3e-9+1e-3)..(3e-9+1e-3),100), range(1..100,100) )
The result looks like this:
Looks like the x-axis is heavily quantized. The Plots package handles the same command just fine:
Plots.scatter( range((-3e-9+1e-3)..(3e-9+1e-3),100), range(1..100,100) )
GLMakie can also handle the same plot if the x range is centered on 0:
GLMakie.scatter( range((-5e-9)..(5e-9),100), range(1..100,100) )
Why is this happening? Does GLMakie use a smaller float for speed? Can I do anything to avoid this?

Does GLMakie use a smaller float for speed?
Yes it does. OpenGL commonly uses 32 bit floats and Makie has been built with Float32 as a result. Right now you'd have normalize your data and adjust ticks manually to fix this. See https://makie.juliaplots.org/stable/examples/layoutables/axis/index.html#modifying_ticks
There are also a bunch of issues regarding this on github, for example https://github.com/JuliaPlots/Makie.jl/issues/1373.

Related

Plotting the normal quantile function with R

I would like to make a graph of the quantile function of the standard normal distribution using R. I use the command
plot(qnorm,ylim=c(-4,4))
and I get this graph
However, the graph that I get is truncated at around $-2$ and around $2$. I would like to see something like this picture
The last picture was generated using the command
plot(1:99999/10^5,qnorm(1:99999/10^5),type="l")
but it is inefficient and slow.
Why is R making the truncated graph? What command should I use to make a graph without truncation?
Any help is much appreciated!
This should be sufficient:
plot(qnorm,from=pnorm(-4),to=pnorm(4))
If you'd like it a bit smoother where the radius of curvature is small, I'd suggest increasing the n parameter a little, e.g.:
plot(qnorm,from=pnorm(-4),to=pnorm(4),n=201)
see ?plot.function and ?curve

plotting voxel image in R

Do you know if it exist libraries or functions in R to plot voxel objects (3D array)?
I found the package rgl that can perform 3d scatter plot, but I am really looking for an equivalent of the function "image" that works with 3D array.
Thanks
Here is a basic example of something using the rgl package. You can easily make it into a function that operates on a 3D array to alter the colour, alpha or other features of interest.
library(rgl)
cubit=cube3d(color="blue", alpha=0.3)
cubit$vb[cubit$vb == -1]= 0
gridx=0:5;gridy=0:5;gridz=0:5
temp=cubit
plot3d(temp,box=FALSE,axes=FALSE,xlab="",ylab="",zlab="")
wire3d(temp,add=TRUE,color="blue",alpha=1)
for(ix in gridx){
for(iy in gridy){
for(iz in gridz){
temp$vb[1,]=cubit$vb[1,]+ix
temp$vb[2,]=cubit$vb[2,]+iy
temp$vb[3,]=cubit$vb[3,]+iz
shade3d(temp,add=TRUE,,alpha=runif(1))
wire3d(temp,add=TRUE,color="blue")
}
}
}
I have used something like this, but I have noted that the memory size grows very quickly (I cannot do more than 60000 voxels, using 3-4Gb RAM). I have tried something similar using cube3D from the plot3D package thinking that a non-interactive plot would (should!) be more memory efficient, but for some reason this package had worse performance (only 1000 voxels). If you have a solid cube, then you can be much smarter about only plotting the outer edges using a ploygon3D plot ... but that is not my case. I am still searching for better performance using R functionality, but thought I should add to this conversation in case of any other wandering souls who cross paths here too.

scaling Venn diagram in R

I am trying to plot the Venn Diagram of intersection of 3 sets with the following function:
library(VennDiagram)
draw.triple.venn(10,5,4,2,3,1,1,ind=TRUE,scaled=TRUE).
In the Quartz window I receive 3 identical circles (all of the same size). Where did the scaling go? After several hours of trying, I am wondering if it is a bug or if maybe the previous settings of my plotting area are not allowing it ( i closed and reopened the Quartz window several times). The output value is:
(polygon[GRID.polygon.1498], polygon[GRID.polygon.1499], polygon[GRID.polygon.1500], polygon[GRID.polygon.1501], polygon[GRID.polygon.1502], polygon[GRID.polygon.1503], text[GRID.text.1504], text[GRID.text.1505], text[GRID.text.1506], text[GRID.text.1507], text[GRID.text.1508], text[GRID.text.1509], text[GRID.text.1510], text[GRID.text.1511], text[GRID.text.1512])
Any help or tip would be appreciated. All the examples I see online are depicted already scaled.
According to the manual, scaling only happens for some configurations. One example would be
draw.triple.venn(1,2,3,0,0,0,0)
On the other hand, looking at the source code of that function, there appears to be no relevant use of that parameter at all. And indeed, passing scale=FALSE to the above command still results in scaled circles.
So it looks like with the current source code, you have no control over scaling, one way or the other.
The scale parameter is being ignored in many cases.
Here is another example that is also not plotted to scale
venn.plot <- draw.triple.venn(1883,598,2151,218,221,611,95, c("AL", "RL", "R"),scale=TRUE)
I used this .jar instead:
http://www.cs.kent.ac.uk/people/staff/pjr/EulerVennCircles/EulerVennApplet.html

rgl plot: point size does not change when saving as postscript

I'm trying to generate a 3d scatterplot using rgl. It looks great on my screen, but whenever I export it as a PDF (or any other postscript format) it completely ignores any size specifications I use.
(I'm running RGui v.2.15.1 and rgl v.0.92.892 on a Macbook under Mountain Lion.)
For example:
library(rgl)
set.seed(1982)
points3d(runif(5),runif(5),runif(5), size=20)
# points look huge
rgl.postscript('testplot.pdf', fmt='pdf')
# points look tiny
Does anyone have an idea for a way to get this to work? The resolution of the images I get using rgl.snapshot don't look so good, and I would really like to get a vector image for this plot.
Also, I followed this thread and I got text to resize just fine, but not points. So I thought one way to work around this would be to plot my points as text using a circle as my character, but I couldn't get rgl to accept symbols or expressions either...
Confirmed on Windows, look like some paper size scaling problem. You might try
spheres3d(runif(5),runif(5),runif(5),radius=0.1)
as a workaround if you can live with real 3d.

R How to make smoother looking plots of oscillations

When plotting oscillations in R, e.g., using the package desolve,
df1 <-function(t,y,mu)( list(c(y[2],mu*y[1]^3-y[1]+0.005*cos(t))))
library (deSolve)
yini<-c(y1=0,y2=0)
df2 <-ode(y=yini,func=df1, times=0:520,parms=0.1667)
plot(df2,type="l",which="y1",ylab="Displacement",xlab="Time", main="")
I get raggedy plots such as:
instead of a smooth plot (not done in R) such as:
Does anyone know of a way to obtain a smoother plot in R instead of a raggedy one when displaying oscillations? Note that it is not just a matter of the difference in scale and I am not looking for a smoothing filter.
Thanks,
I generated your plot in R and exported it as PDF. I zoomed in on it and it's quite lovely. I can't see the problem you're talking about there. Therefore, there are some scaling issues or something with a raster format that are causing the issue. Perhaps you're pasting into Word and that's giving you a raster image that's bad. The plot that R is making, at a logical level, is great in spite of the one you posted. It's even better than the comparison plot you put up.
It's possible that you're generating the plot in a raster format and not setting a high enough resolution and size. Try tiff('filname', 1200, 1200, 300) for a good raster image of it. I did notice that when exporting to raster formats it was easy to make your plot into a fine mess with default png or jpg settings that would just smear things.
Maybe you really wanted to sample in your function at a higher resolution, something not done in the comparison plot. If that's the case then it's relatively easy. Change 0:520 to seq(0, 520, 0.1). That's an even nicer plot, as shown below (much better than shown as PDF, EPS, or SVG).

Resources