# Error using Plot in Julia

**URL:** <https://discourse.julialang.org/t/error-using-plot-in-julia/22809>\
**Category:** Visualization\
**Tags:** plotting\
**Created:** [April 5, 2019, 4:51pm UTC](https://discourse.julialang.org/t/error-using-plot-in-julia/22809 "2019-04-05T16:51:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ennvvy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ennvvy/32/7816_2.png) [@ennvvy](https://discourse.julialang.org/u/ennvvy)\
**Post date:** [April 5, 2019, 4:51pm UTC](https://discourse.julialang.org/t/error-using-plot-in-julia/22809/1 "2019-04-05T16:51:15Z")

</div>

I get an error every time I try plotting in Julia. The code I have been using to generate the histograms is as below:

```julia
using StatsBase

using Plots

a = reshape(intl,(500*100)) ;

plt1 = fit(Histogram,a,30:10:150) ;

plot(plt1,xticks=30:10:150,xlim(30,150)) ;

```

The error is as follows:

ERROR: PyError ($(Expr(:escape, :(ccall(#= /home/nv/.julia/packages/PyCall/a5Jd3/src/pyfncall.jl:44 =# @pysym(:PyObject\_Call), PyPtr, (PyPtr, PyPtr, PyPtr), o, pyargsptr, kw))))) \<class ‘RuntimeError’\>  
RuntimeError(‘Julia exception: MethodError: no method matching iterate(::Histogram{Int64,1,Tuple{StepRange{Int64,Int64}}})\nClosest candidates are:\n iterate(!Matched::Core.SimpleVector) at essentials.jl:568\n iterate(!Matched::Core.SimpleVector, !Matched::Any) at essentials.jl:568\n iterate(!Matched::ExponentialBackOff) at error.jl:199\n …\nStacktrace:\n [1] jlwrap\_iterator(::Histogram{Int64,1,Tuple{StepRange{Int64,Int64}}}) at /home/nv/.julia/packages/PyCall/a5Jd3/src/pyiterator.jl:150\n [2] pyjlwrap\_getiter(::Ptr{PyCall.PyObject\_struct}) at /home/nv/.julia/packages/PyCall/a5Jd3/src/pyiterator.jl:131\n [3] macro expansion at /home/nv/.julia/packages/PyCall/a5Jd3/src/exception.jl:81 [inlined]\n [4] \_\_pycall!(::PyCall.PyObject, ::Ptr{PyCall.PyObject\_struct}, ::PyCall.PyObject, ::PyCall.PyObject) at /home/nv/.julia/packages/PyCall/a5Jd3/src/pyfncall.jl:44\n [5] \_pycall!(::PyCall.PyObject, ::PyCall.PyObject, ::Tuple{Histogram{Int64,1,Tuple{StepRange{Int64,Int64}}},Tuple{Int64,Int64}}, ::Int64, ::PyCall.PyObject) at /home/nv/.julia/packages/PyCall/a5Jd3/src/pyfncall.jl:29\n [6] \_pycall!(::PyCall.PyObject, ::PyCall.PyObject, ::Tuple{Histogram{Int64,1,Tuple{StepRange{Int64,Int64}}},Tuple{Int64,Int64}}, ::Base.Iterators.Pairs{Symbol,StepRange{Int64,Int64},Tuple{Symbol},NamedTuple{(:xticks,),Tuple{StepRange{Int64,Int64}}}}) at /home/nv/.julia/packages/PyCall/a5Jd3/src/pyfncall.jl:11\n [7] #pycall#110(::Base.Iterators.Pairs{Symbol,StepRange{Int64,Int64},Tuple{Symbol},NamedTuple{(:xticks,),Tuple{StepRange{Int64,Int64}}}}, ::Function, ::PyCall.PyObject, ::Type{PyCall.PyAny}, ::Histogram{Int64,1,Tuple{StepRange{Int64,Int64}}}, ::Vararg{Any,N} where N) at /home/nv/.julia/packages/PyCall/a5Jd3/src/pyfncall.jl:86\n [8] (::getfield(PyCall, Symbol(“#kw##pycall”)))(::NamedTuple{(:xticks,),Tuple{StepRange{Int64,Int64}}}, ::typeof(PyCall.pycall), ::PyCall.PyObject, ::Type{PyCall.PyAny}, ::Histogram{Int64,1,Tuple{StepRange{Int64,Int64}}}, ::Vararg{Any,N} where N) at ./none:0\n [9] #plot#85(::Base.Iterators.Pairs{Symbol,StepRange{Int64,Int64},Tuple{Symbol},NamedTuple{(:xticks,),Tuple{StepRange{Int64,Int64}}}}, ::Function, ::Histogram{Int64,1,Tuple{StepRange{Int64,Int64}}}, ::Vararg{Any,N} where N) at /home/nv/.julia/packages/PyPlot/KRYZs/src/PyPlot.jl:178\n [10] (::getfield(PyPlot, Symbol(“#kw##plot”)))(::NamedTuple{(:xticks,),Tuple{StepRange{Int64,Int64}}}, ::typeof(plot), ::Histogram{Int64,1,Tuple{StepRange{Int64,Int64}}}, ::Vararg{Any,N} where N) at ./none:0\n [11] top-level scope at none:0\n [12] eval at ./boot.jl:328 [inlined]\n [13] repleval(::Module, ::Expr) at /home/nv/.julia/packages/Atom/mngyX/src/repl.jl:147\n [14] (::getfield(Atom, Symbol(“##168#170”)){Module})() at /home/nv/.julia/packages/Atom/mngyX/src/repl.jl:182\n [15] with\_logstate(::getfield(Atom, Symbol(“##168#170”)){Module}, ::Base.CoreLogging.LogState) at ./logging.jl:395\n [16] with\_logger at ./logging.jl:491 [inlined]\n [17] evalrepl(::Module, ::String) at /home/nv/.julia/packages/Atom/mngyX/src/repl.jl:173\n [18] top-level scope at /home/nv/.julia/packages/Atom/mngyX/src/repl.jl:216\n [19] eval(::Module, ::Any) at ./boot.jl:328\n [20] eval\_user\_input(::Any, ::REPL.REPLBackend) at /buildworker/worker/package\_linux64/build/usr/share/julia/stdlib/v1.1/REPL/src/REPL.jl:85\n [21] macro expansion at /buildworker/worker/package\_linux64/build/usr/share/julia/stdlib/v1.1/REPL/src/REPL.jl:117 [inlined]\n [22] (::getfield(REPL, Symbol(“##26#27”)){REPL.REPLBackend})() at ./task.jl:259’)  
File “/home/nv/.julia/conda/3/lib/python3.7/site-packages/matplotlib/pyplot.py”, line 2811, in plot  
is not None else {}), \*\*kwargs)  
File “/home/nv/.julia/conda/3/lib/python3.7/site-packages/matplotlib/ **init**.py”, line 1810, in inner  
return func(ax, \*args, \*\*kwargs)  
File “/home/nv/.julia/conda/3/lib/python3.7/site-packages/matplotlib/axes/\_axes.py”, line 1611, in plot  
for line in self.\_get\_lines(\*args, \*\*kwargs):  
File “/home/nv/.julia/conda/3/lib/python3.7/site-packages/matplotlib/axes/\_base.py”, line 393, in \_grab\_next\_args  
yield from self.\_plot\_args(this, kwargs)  
File “/home/nv/.julia/conda/3/lib/python3.7/site-packages/matplotlib/axes/\_base.py”, line 370, in \_plot\_args  
x, y = self.\_xy\_from\_xy(x, y)  
File “/home/nv/.julia/conda/3/lib/python3.7/site-packages/matplotlib/axes/\_base.py”, line 204, in \_xy\_from\_xy  
bx = self.axes.xaxis.update\_units(x)  
File “/home/nv/.julia/conda/3/lib/python3.7/site-packages/matplotlib/axis.py”, line 1467, in update\_units  
converter = munits.registry.get\_converter(data)  
File “/home/nv/.julia/conda/3/lib/python3.7/site-packages/matplotlib/units.py”, line 181, in get\_converter  
converter = self.get\_converter(next\_item)  
File “/home/nv/.julia/conda/3/lib/python3.7/site-packages/matplotlib/units.py”, line 187, in get\_converter  
thisx = safe\_first\_element(x)  
File “/home/nv/.julia/conda/3/lib/python3.7/site-packages/matplotlib/cbook/ **init**.py”, line 1637, in safe\_first\_element  
return next(iter(obj))

Stacktrace:  
[1] pyerr\_check at /home/nv/.julia/packages/PyCall/a5Jd3/src/exception.jl:60 [inlined]  
[2] pyerr\_check at /home/nv/.julia/packages/PyCall/a5Jd3/src/exception.jl:64 [inlined]  
[3] macro expansion at /home/nv/.julia/packages/PyCall/a5Jd3/src/exception.jl:84 [inlined]  
[4] \_\_pycall!(::PyCall.PyObject, ::Ptr{PyCall.PyObject\_struct}, ::PyCall.PyObject, ::PyCall.PyObject) at /home/nv/.julia/packages/PyCall/a5Jd3/src/pyfncall.jl:44  
[5] \_pycall!(::PyCall.PyObject, ::PyCall.PyObject, ::Tuple{Histogram{Int64,1,Tuple{StepRange{Int64,Int64}}},Tuple{Int64,Int64}}, ::Int64, ::PyCall.PyObject) at /home/nv/.julia/packages/PyCall/a5Jd3/src/pyfncall.jl:29  
[6] \_pycall!(::PyCall.PyObject, ::PyCall.PyObject, ::Tuple{Histogram{Int64,1,Tuple{StepRange{Int64,Int64}}},Tuple{Int64,Int64}}, ::Base.Iterators.Pairs{Symbol,StepRange{Int64,Int64},Tuple{Symbol},NamedTuple{(:xticks,),Tuple{StepRange{Int64,Int64}}}}) at /home/nv/.julia/packages/PyCall/a5Jd3/src/pyfncall.jl:11  
[7] #pycall#110(::Base.Iterators.Pairs{Symbol,StepRange{Int64,Int64},Tuple{Symbol},NamedTuple{(:xticks,),Tuple{StepRange{Int64,Int64}}}}, ::Function, ::PyCall.PyObject, ::Type{PyCall.PyAny}, ::Histogram{Int64,1,Tuple{StepRange{Int64,Int64}}}, ::Vararg{Any,N} where N) at /home/nv/.julia/packages/PyCall/a5Jd3/src/pyfncall.jl:86  
[8] (::getfield(PyCall, Symbol(“#kw##pycall”)))(::NamedTuple{(:xticks,),Tuple{StepRange{Int64,Int64}}}, ::typeof(PyCall.pycall), ::PyCall.PyObject, ::Type{PyCall.PyAny}, ::Histogram{Int64,1,Tuple{StepRange{Int64,Int64}}}, ::Vararg{Any,N} where N) at ./none:0  
[9] #plot#85(::Base.Iterators.Pairs{Symbol,StepRange{Int64,Int64},Tuple{Symbol},NamedTuple{(:xticks,),Tuple{StepRange{Int64,Int64}}}}, ::Function, ::Histogram{Int64,1,Tuple{StepRange{Int64,Int64}}}, ::Vararg{Any,N} where N) at /home/nv/.julia/packages/PyPlot/KRYZs/src/PyPlot.jl:178  
[10] (::getfield(PyPlot, Symbol(“#kw##plot”)))(::NamedTuple{(:xticks,),Tuple{StepRange{Int64,Int64}}}, ::typeof(plot), ::Histogram{Int64,1,Tuple{StepRange{Int64,Int64}}}, ::Vararg{Any,N} where N) at ./none:0  
[11] top-level scope at none:0

---

<div class="post-metadata">

**Author:** ![stillyslalom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stillyslalom/32/45687_2.png) [@stillyslalom](https://discourse.julialang.org/u/stillyslalom)\
**Post date:** [April 5, 2019, 5:03pm UTC](https://discourse.julialang.org/t/error-using-plot-in-julia/22809/2 "2019-04-05T17:03:42Z")

</div>

What package versions are you using (use `]st` to get package status)? Your code works for me. Note that the semicolons are unnecessary in Julia:

```julia
using Plots, StatsBase
hist_data = vec(rand(30:1:150, 500, 100))
plot(fit(Histogram, hist_data, 30:10:150), xticks=30:10:150, xlim=(30, 150))

```

---

<div class="post-metadata">

**Author:** ![ennvvy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ennvvy/32/7816_2.png) [@ennvvy](https://discourse.julialang.org/u/ennvvy)\
**Post date:** [April 5, 2019, 5:23pm UTC](https://discourse.julialang.org/t/error-using-plot-in-julia/22809/3 "2019-04-05T17:23:56Z")

</div>

I tried running your code and get the same error mentioned earlier. This is the output I get on using `]st`

Status `~/.julia/environments/v1.1/Project.toml`  
[c52e3926] Atom v0.8.2  
[6e4b80f9] BenchmarkTools v0.4.2  
[a93c6f00] DataFrames v0.17.1  
[aaf54ef3] DistributedArrays v0.6.0  
[31c24e10] Distributions v0.17.0  
[89b67f3b] ExcelFiles v0.9.1  
[c91e804a] Gadfly v1.0.1  
[a2cc645c] GraphPlot v0.3.1  
[f67ccb44] HDF5 v0.11.0  
[7073ff75] IJulia v1.18.0  
[4138dd39] JLD v0.9.1  
[e5e0dc1b] Juno v0.7.0  
[093fc24a] LightGraphs v1.2.0  
[56b0d19f] OdsIO v0.5.0  
[91a5bcdd] Plots v0.23.2  
[438e738f] PyCall v1.91.1  
[d330b81b] PyPlot v2.8.0  
[3cdcf5f2] RecipesBase v0.6.0  
[2913bbd2] StatsBase v0.29.0  
[f3b207a7] StatsPlots v0.10.2  
[37b6cedf] Traceur v0.3.0  
[fdbf4ff8] XLSX v0.4.7  
[8ba89e20] Distributed  
[9abbd945] Profile  
[1a1011a3] SharedArrays

---

<div class="post-metadata">

**Author:** ![stillyslalom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stillyslalom/32/45687_2.png) [@stillyslalom](https://discourse.julialang.org/u/stillyslalom)\
**Post date:** [April 5, 2019, 6:09pm UTC](https://discourse.julialang.org/t/error-using-plot-in-julia/22809/4 "2019-04-05T18:09:27Z")

</div>

1. Update your packages and `]build`; there’s a more recent release of `Plots.jl` that may fix your issue
2. Try a simpler plot, e.g. `plot(1:10)`: the histogram recipe might be broken
3. Switch backends: first `]add GR`, then `using Plots; gr()`

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [April 5, 2019, 6:12pm UTC](https://discourse.julialang.org/t/error-using-plot-in-julia/22809/5 "2019-04-05T18:12:11Z")

</div>

It looks as if something is wrong in your pyplot installation - changing the backend to gr should solve it.  
Try to plot something with pyplot (without using Plots) - if that fails too you might open an issue on the pyplot repo.

---

<div class="post-metadata">

**Author:** ![WILSON\_MASIH](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wilson_masih/32/7719_2.png) [@WILSON\_MASIH](https://discourse.julialang.org/u/WILSON_MASIH)\
**Post date:** [April 5, 2019, 8:24pm UTC](https://discourse.julialang.org/t/error-using-plot-in-julia/22809/6 "2019-04-05T20:24:10Z")

</div>

you are working on which version?
