# Surface Plots

**URL:** <https://discourse.julialang.org/t/surface-plots/7161>\
**Category:** General Usage\
**Tags:** plotting, pyplot, matlab\
**Created:** [November 19, 2017, 1:30am UTC](https://discourse.julialang.org/t/surface-plots/7161 "2017-11-19T01:30:13Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Romero\_Azzalini](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/romero_azzalini/32/10325_2.png) [@Romero\_Azzalini](https://discourse.julialang.org/u/Romero_Azzalini)\
**Post date:** [November 19, 2017, 1:30am UTC](https://discourse.julialang.org/t/surface-plots/7161/1 "2017-11-19T01:30:13Z")

</div>

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

 ![density](https://global.discourse-cdn.com/julialang/original/3X/0/b/0bf286438320f0d2a159945050383a3720c27c4d.png)  
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 ☹

Best,  
Hannes

---

<div class="post-metadata">

**Author:** ![JackDevine](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jackdevine/32/1048_2.png) [@JackDevine](https://discourse.julialang.org/u/JackDevine)\
**Post date:** [November 19, 2017, 1:53am UTC](https://discourse.julialang.org/t/surface-plots/7161/2 "2017-11-19T01:53:23Z")

</div>

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.

```julia
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:

```julia
using Plots; pyplot()

heatmap(rand(30, 30))

```

---

<div class="post-metadata">

**Author:** ![Romero\_Azzalini](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/romero_azzalini/32/10325_2.png) [@Romero\_Azzalini](https://discourse.julialang.org/u/Romero_Azzalini)\
**Post date:** [November 19, 2017, 2:37am UTC](https://discourse.julialang.org/t/surface-plots/7161/3 "2017-11-19T02:37:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![JackDevine](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jackdevine/32/1048_2.png) [@JackDevine](https://discourse.julialang.org/u/JackDevine)\
**Post date:** [November 19, 2017, 5:23am UTC](https://discourse.julialang.org/t/surface-plots/7161/4 "2017-11-19T05:23:32Z")

</div>

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](https://github.com/JuliaPy/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](https://github.com/jheinen/GR.jl), [PlotlyJS](https://github.com/sglyon/PlotlyJS.jl) and [Gadfly](https://github.com/GiovineItalia/Gadfly.jl). 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](https://github.com/JuliaPlots/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:

```julia
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](http://docs.juliaplots.org/latest/), because it is really good, although maybe not quite as extensive as something like matlab or matplotlib.

---

<div class="post-metadata">

**Author:** ![Romero\_Azzalini](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/romero_azzalini/32/10325_2.png) [@Romero\_Azzalini](https://discourse.julialang.org/u/Romero_Azzalini)\
**Post date:** [November 20, 2017, 5:12pm UTC](https://discourse.julialang.org/t/surface-plots/7161/5 "2017-11-20T17:12:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![chakravala](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chakravala/32/6832_2.png) [@chakravala](https://discourse.julialang.org/u/chakravala)\
**Post date:** [November 20, 2017, 6:14pm UTC](https://discourse.julialang.org/t/surface-plots/7161/6 "2017-11-20T18:14:18Z")

</div>

you can lookup color map names here: [https://matplotlib.org/examples/color/colormaps\_reference.html](https://matplotlib.org/examples/color/colormaps_reference.html)

and apply them on `imshow` like this:

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

```

---

<div class="post-metadata">

**Author:** ![jacob-roth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jacob-roth/32/1862_2.png) [@jacob-roth](https://discourse.julialang.org/u/jacob-roth)\
**Post date:** [November 2, 2018, 9:03pm UTC](https://discourse.julialang.org/t/surface-plots/7161/7 "2018-11-02T21:03:09Z")

</div>

How can I add a colorbar to a `subplot`? For example, I need to call `hist2d` which is accessible through `ax`

```julia
using PyPlot
PyPlot.clf()
(fig,ax)=PyPlot.subplots(1,1)
im=ax[:hist2d](rand(1000), rand(1000), 100, cmap=ColorMap("viridis"))

```

So I have to call `colorbar` through `fig` according to something like: `fig[:colorbar](im,ax=ax)`, but this gives me an error. What should I do instead?

---

<div class="post-metadata">

**Author:** ![jacob-roth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jacob-roth/32/1862_2.png) [@jacob-roth](https://discourse.julialang.org/u/jacob-roth)\
**Post date:** [November 2, 2018, 9:15pm UTC](https://discourse.julialang.org/t/surface-plots/7161/8 "2018-11-02T21:15:29Z")

</div>

Ah, [here](https://github.com/JuliaPy/PyPlot.jl/issues/142)’s the answer:

```julia
fig[:colorbar](im[4], ax=ax)

```
