1

I have used filled contour to convert a matrix into an image with a color gradient. enter image description here The names of my axes show on the plot but not the scale and values. The plot.axes function does not return any error but doesn't add anything to my plot so I guess there is an issue with that (my x-axis ranges from 350 to 500 and my y from 200 to 450 based on my matrix) Here is the code I used:

filled.contour(matrix, 
               color.palette = colorRampPalette(c("blue", "green",
                                          "yellow","orange","red")), 
               main = "Spectre 3D Puyricard",  
               xlab = "émission",
               ylab = "excitation", 
               plot.axes={ axis(1, seq(350, 500, by = 10)) 
               axis(2, seq(200, 450, by = 10)) })

What is wrong with it?

Thanks

user2554330
  • 37,248
  • 4
  • 43
  • 90
Janet
  • 21
  • 2
  • Why is this tagged both R and Python? Without any data it's unclear exactly what's wrong. You also might have a syntax error in the `plot.axes` argument – camille Jun 10 '21 at 15:28

1 Answers1

1

You didn't specify the x and y arguments, so they will be taken to run from 0 to 1. The axes you asked for won't show up in that range. So what you should do is set

x <- seq(350, 500, length=nrow(matrix))
y <- seq(200, 450, length=ncol(matrix))

and then give both in the call to plot:

filled.contour(x, y, matrix, 
               color.palette = colorRampPalette(c("blue", "green",
                                          "yellow","orange","red")), 
               main = "Spectre 3D Puyricard",  
               xlab = "émission",
               ylab = "excitation")

I left off the plot.axes argument because the defaults might be good enough, but you could add it back if you don't like the choice of tick marks or something.

user2554330
  • 37,248
  • 4
  • 43
  • 90
  • Thank you so much! It works but I don' t know why since yesterday I have another issue, the box on the right that shows the color gradient ranges from 0 to 500 instead of 0-100 and as a result the red colors don't show on the plot anymore as my matrix values no more than 100. I tried code with "key.axes" but I can't get the same box as the one I posted yesterday :( – Janet Jun 11 '21 at 13:50
  • You could post that as a different question, but this time include some data, e.g. a fake `matrix` dataset that illustrates the problem. Without a reproducible example, it's really hard to guess what's going wrong. – user2554330 Jun 11 '21 at 19:06