# Plotting from vscode

**URL:** <https://discourse.julialang.org/t/plotting-from-vscode/12009>\
**Category:** New to Julia\
**Tags:** plotting\
**Created:** [June 27, 2018, 7:09pm UTC](https://discourse.julialang.org/t/plotting-from-vscode/12009 "2018-06-27T19:09:32Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![sbacelar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sbacelar/32/4359_2.png) [@sbacelar](https://discourse.julialang.org/u/sbacelar)\
**Post date:** [June 27, 2018, 7:09pm UTC](https://discourse.julialang.org/t/plotting-from-vscode/12009/1 "2018-06-27T19:09:32Z")

</div>

I am trying a simple plot using `vscode`:

```julia
using PyPlot
x = linspace(0, 10, 200); y = sin.(x);
plot(x, y, "b-", linewidth=2)

```

And the result is simply PyObject `<matplotlib.lines.Line2D object at 0x1249b77f0>` and no graph!  
I tried the same in Jupyter and the graph is showed. Why?

---

<div class="post-metadata">

**Author:** ![HCrepaz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hcrepaz/32/4531_2.png) [@HCrepaz](https://discourse.julialang.org/u/HCrepaz)\
**Post date:** [June 27, 2018, 8:38pm UTC](https://discourse.julialang.org/t/plotting-from-vscode/12009/2 "2018-06-27T20:38:35Z")

</div>

First I would try if you can display the current figure with: `display(gcf())`  
If nothing appears you may have to install a Python GUI toolkit as it is outlined in the documentation:  
[https://github.com/JuliaPy/PyPlot.jl](https://github.com/JuliaPy/PyPlot.jl)

---

<div class="post-metadata">

**Author:** ![sbacelar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sbacelar/32/4359_2.png) [@sbacelar](https://discourse.julialang.org/u/sbacelar)\
**Post date:** [June 27, 2018, 9:32pm UTC](https://discourse.julialang.org/t/plotting-from-vscode/12009/3 "2018-06-27T21:32:54Z")

</div>

Thank you. `display(gcf())` shows the current figure.

---

<div class="post-metadata">

**Author:** ![Daneel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/daneel/32/175_2.png) [@Daneel](https://discourse.julialang.org/u/Daneel)\
**Post date:** [June 28, 2018, 9:00am UTC](https://discourse.julialang.org/t/plotting-from-vscode/12009/4 "2018-06-28T09:00:44Z")

</div>

If you’re going to be doing a lot of interactive plotting then it’s better to turn on the interactive plotting mode.

```julia
using PyPlot
ion()
...

```

After that `display(gcf())` should not be necessary.

---

<div class="post-metadata">

**Author:** ![sbacelar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sbacelar/32/4359_2.png) [@sbacelar](https://discourse.julialang.org/u/sbacelar)\
**Post date:** [June 28, 2018, 9:51am UTC](https://discourse.julialang.org/t/plotting-from-vscode/12009/5 "2018-06-28T09:51:08Z")

</div>

I tried do plot with `ion()` and without `display(gif())`with no success.

---

<div class="post-metadata">

**Author:** ![davidanthoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidanthoff/32/223493_2.png) [@davidanthoff](https://discourse.julialang.org/u/davidanthoff)\
**Post date:** [June 29, 2018, 5:41am UTC](https://discourse.julialang.org/t/plotting-from-vscode/12009/6 "2018-06-29T05:41:16Z")

</div>

[https://github.com/JuliaEditorSupport/julia-vscode/issues/325](https://github.com/JuliaEditorSupport/julia-vscode/issues/325)

---

<div class="post-metadata">

**Author:** ![HCrepaz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hcrepaz/32/4531_2.png) [@HCrepaz](https://discourse.julialang.org/u/HCrepaz)\
**Post date:** [June 29, 2018, 8:29am UTC](https://discourse.julialang.org/t/plotting-from-vscode/12009/7 "2018-06-29T08:29:05Z")

</div>

Another possibility is to use **PyPlot** as the plotting backend with **Plots.jl**.  
Then calling `display(gcf())` is not necessary and VS Code shows the plot immediately.  
Added to this is the benefit that you can switch easilly to one of the 15 different plotting backends.

```julia
using Plots
pyplot()
x = linspace(0,2*pi,1000); y = sin.(3 * x + 4 * cos.(2 * x));
plot(x, y, color="blue", w=2)

```

---

<div class="post-metadata">

**Author:** ![sbacelar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sbacelar/32/4359_2.png) [@sbacelar](https://discourse.julialang.org/u/sbacelar)\
**Post date:** [June 29, 2018, 9:55am UTC](https://discourse.julialang.org/t/plotting-from-vscode/12009/8 "2018-06-29T09:55:54Z")

</div>

Yes it seems a better solution.  
But I noticed that the syntax for the command `plot`has changed: `color` and `w`instead of “b-“ and `line width`.

Is it due to `Plots` package?

---

<div class="post-metadata">

**Author:** ![HCrepaz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hcrepaz/32/4531_2.png) [@HCrepaz](https://discourse.julialang.org/u/HCrepaz)\
**Post date:** [June 29, 2018, 10:10am UTC](https://discourse.julialang.org/t/plotting-from-vscode/12009/9 "2018-06-29T10:10:26Z")

</div>

Plots.jl is a common interface to the various backends. Not all the keywords for all backends are supported though. A dedicated list of supported attributes is provided in the documentation to the package.  
Some examples for PyPlot are here:  
[http://docs.juliaplots.org/latest/examples/pyplot/](http://docs.juliaplots.org/latest/examples/pyplot/)

---

<div class="post-metadata">

**Author:** ![sbacelar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sbacelar/32/4359_2.png) [@sbacelar](https://discourse.julialang.org/u/sbacelar)\
**Post date:** [June 29, 2018, 10:35am UTC](https://discourse.julialang.org/t/plotting-from-vscode/12009/10 "2018-06-29T10:35:32Z")

</div>

Thank you for showing me the link to the `Plots` site. It is very interesting and useful.

---

<div class="post-metadata">

**Author:** ![jar](https://avatars.discourse-cdn.com/v4/letter/j/45deac/32.png) [@jar](https://discourse.julialang.org/u/jar)\
**Post date:** [August 19, 2019, 5:52am UTC](https://discourse.julialang.org/t/plotting-from-vscode/12009/11 "2019-08-19T05:52:12Z")

</div>

Hello fiolks.  
I have this piece of code that works in REPL, but not in vscode.

using TestImages  
img = testimage(‘cameraman’)  
plot(img)

Why?, Any ideas?

---

<div class="post-metadata">

**Author:** ![jar](https://avatars.discourse-cdn.com/v4/letter/j/45deac/32.png) [@jar](https://discourse.julialang.org/u/jar)\
**Post date:** [August 19, 2019, 6:29am UTC](https://discourse.julialang.org/t/plotting-from-vscode/12009/12 "2019-08-19T06:29:02Z")

</div>

now I see that I need to use ImageView.  
I open another thread…
