Giter VIP home page Giter VIP logo

Comments (12)

baddstats avatar baddstats commented on June 1, 2024

At present, reversing the order of ylim in a call to plot.owin only has an effect inside that plot call and not in subsequent plot commands. I'll investigate whether it's possible to cause a side-effect that persists in subsequent plot commands, but this may depend on the plot device.

For now, your best solution is to actually flip the objects W and X using affine()

from spatstat.

baddstats avatar baddstats commented on June 1, 2024

My comments above are incorrect - reversing the order of ylim in the call to plot.owin causes the coordinate system to be flipped (as one can check by inspecting par("usr") for example), and this coordinate system should be respected by subsequent plots when add=TRUE. So this is a bug somewhere, not a missing feature.

Could you please try adding the argument useRaster=FALSE to the image plot, i.e.

plot(density(X,adjust=0.2), add=TRUE, useRaster=FALSE)

Please try in the cases where you were getting the wrong behaviour before. This will give us a good idea whether it's a bug in the device driver.

from spatstat.

Bio7 avatar Bio7 commented on June 1, 2024

Thanks for the fast reply and analysis.
Indeed, the argument useRaster=FALSE did the trick.
plot(density(X,adjust=0.2),add=T,useRaster=F)
I tested the command on MacOSX and now it is displayed correctly.

Result:
densityplot

Only the legend in the density plot is missing. But this is a result of the created axis and master plot I think.

from spatstat.

baddstats avatar baddstats commented on June 1, 2024

OK, thank you. So the fix is to set useRaster=FALSE when plotting the image.

This suggests that there is a bug in R's image display code (graphics::rasterImage) which I will chase up.

To get the legend in the image plot in your example, you can set show.all=TRUE. See help(plot.im)

from spatstat.

baddstats avatar baddstats commented on June 1, 2024

This appears to be a known R bug that was thought to have been repaired but is now happening again on some devices. I will pursue it. Thanks again for drawing this to our attention.

from spatstat.

baddstats avatar baddstats commented on June 1, 2024

The following code provides an example demonstrating the problem, that does not use spatstat at all.

M <- c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,
   1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0,
   1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0,
   0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1,
   1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1,
   1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0,
   0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1,
   1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1,
   1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
   0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1,
   1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0,
   0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1,
   1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0,
   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1,
   1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)

M <- matrix(M, 16, 21)

tryone <- function(flip=TRUE, raz=TRUE) {
  xl <- yl <- c(0,1)
  if(flip) xl <- rev(xl)
  plot(0,0,xlim=xl ,ylim=yl, type="n", xlab="", ylab="",
      main=paste("flip =", flip, ", useRaster =", raz))
  xx <- seq(0,1,length=16)
  yy <- seq(0,1,length=21)
  image(xx, yy, M, add=TRUE, useRaster=raz)
}

tryall <- function() {
  opa <- par(mfrow=c(2,2))
  tryone(FALSE, FALSE)
  tryone(FALSE, TRUE)
  tryone(TRUE, FALSE)
  tryone(TRUE, TRUE)
  par(opa)
  invisible(NULL)
}

tryall()

from spatstat.

baddstats avatar baddstats commented on June 1, 2024

It seems unlikely that this bug in the device drivers will be fixed soon. The bug tracker says that this bug was reported in 2014. The R help files for image.default and rasterImage contain disclaimers about the rendering of images on some devices.

from spatstat.

Bio7 avatar Bio7 commented on June 1, 2024

Thanks for the analysis and the example. So the solution at the moment is to use the raster argument.

Apropos, the argument show.all=TRUE only works if I plot the density in a default main plot. If I add it to an existing plot (see code above) it isn't displayed.

from spatstat.

baddstats avatar baddstats commented on June 1, 2024

Apropos, the argument show.all=TRUE only works if I plot the density in a default main plot. If I add it to an existing plot (see code above) it isn't displayed.

Hmm, ... that is supposed to work..... I can only imagine that perhaps the originally-declared plot area is not large enough to contain the ribbon at the intended position. Could you please try the original code but just insert W <- grow.rectangle(Frame(W), 0.2 * shortside(Frame(W))) before the plot commands, and then see if show.all=TRUE is working?

from spatstat.

baddstats avatar baddstats commented on June 1, 2024

In the current development version of spatstat I have given plot.im an extra argument workaround which should also fix the problem of incorrect spatial orientation of the image. Set workaround=TRUE to apply the workaround - but only when you know that the device driver is showing the image incorrectly.

from spatstat.

Bio7 avatar Bio7 commented on June 1, 2024

Yes you are right. if I increase the plot area it is displayed.
Here the result with 0.1:

X<- ppp(Particles$X, Particles$Y, c(0,imageSizeX), c(0,imageSizeY))
W <- Window(X)
W <- grow.rectangle(Frame(W), 0.1 * shortside(Frame(W)))
#Plot is visualized in ImageJ (Java) coordinates so we need an inverted coordinate parent plot!
plot(W, ylim=rev(W$yrange),main=NULL)
#Add a density plot and avoiding a main title here!
plot(density(X,adjust=0.2),add=T,useRaster=FALSE,show.all=TRUE,main="")
#Add the points!
plot(X, add=T)
#Add axis and title in custom font size!
axis(1,cex.axis=2)
axis(2, cex.axis=2)
title(main="Density",xlab="Width", ylab="Height", cex.lab=1.5,cex.main=3) 

densityplot

Great, thanks, also for the workaround.

from spatstat.

baddstats avatar baddstats commented on June 1, 2024

That's good!

I've also upgraded grow.rectangle so that instead of grow.rectangle(W, 0.1 * shortside(Frame(W))) you can now just type grow.rectangle(W, fraction=0.1)

I think we can close this issue now.

from spatstat.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.