Error using Plot in Julia

plotting
#1

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

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

#2

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:

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))
#3

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

#4
  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()
1 Like
#5

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.

#6

you are working on which version?