Surface Plots

plotting
pyplot
matlab

#1

Hi,
has anybody an idea how to make such surface plots


I have stored the data in files (one format is x-y-z component). But I have also the format (600x600 grid with the entry of every point in the grid). For the latter I can use Imshow to see the shape, but not for values etc?
I would love to have the data displayed in a similar plot.

I hope somebody can help me :frowning:

Best,
Hannes


#2

I don’t think that either of those are surface plots, I actually don’t understand the first one at all and the second one is usually called a heatmap. With regards to imshow from PyPlot.jl, if you want it to see the scale of your data, then you need to type colorbar() after your plot.

using PyPlot

imshow(rand(30, 30))
colorbar()

On the other hand, if you use heatmap from Plots.jl, then the colorbar is shown by default:

using Plots; pyplot()

heatmap(rand(30, 30))

#3

Hi,
thank you!! Can you tell me, how I set the properties of colorbar(). If I want to set a certain range (e.g. from 150 to 300). And set it to another cmap. Code examples would help, I’m pretty new to Julia


#4

In Julia, there are a bunch of ways to do plotting and none of them are standard, so plotting is a little daunting at first. One package that we have already mentioned here is PyPlot.jl, which is a really good wrapper over the python matplotlib library. PyPlot.jl is very similar to matplotlib, which in turn is kind of similar to plotting in matlab. There are many other really good packages for plotting in Julia, like GR, PlotlyJS and Gadfly. Each of these has a slightly different way of doing things and comes with it’s own advantages and disadvantages.

This is where Plots.jl comes in, by itself, Plots.jl cannot do any plotting, but it can call other plotting libraries in Julia and get them to do the plotting. Essentially, Plots.jl is a unified interface for plotting in Julia and in my opinion it has the most intuitive interface out of all of the libraries that I have mentioned. The way that it works is that you load Plots.jl, tell it what backend you would like it to use and then start plotting. So for example, if you want to use the PyPlot backend to make a heatmap of random data sampled from [0,\,1], but you only want to see the data in the range [0,\,0.3] and you want to use the magma colormap, then you do the following:

using Plots; pyplot()

heatmap(rand(30, 30), clim=(0.0, 0.3), color=:magma)

If you then decide that you want to see the same thing with GR, then you type gr() and remake your plot. I would personally recommend Plots.jl if you are just starting out and you don’t have a specific reason to use one of the other packages.

Also, definitely check out their documentation, because it is really good, although maybe not quite as extensive as something like matlab or matplotlib.


#5

Hi,
thank you for your help! The command I was searching for the colormaps was “get_cmaps()”. You can set up the range of the colorscale with vmin=… and vmax=… I don’t know how to set up the ticks though, if you want to personalize the scale, nor how to create your own cmap with a bunch of lines (from white to yellow, orange and red e.g.). What I found kind of usefull was _r as an extend to the cmap name to reverse the colorscheme.

Best,
Hannes


#6

you can lookup color map names here: https://matplotlib.org/examples/color/colormaps_reference.html

and apply them on imshow like this:

using PyPlot
imshow(data, cmap="name")
colorbar()