I’d like to adjust bin count. After using Gadfly, the plot() became undefined.
using Distributions
function a()
jump=rand(TDist(1),10000)#12>10
for j in 1:length(jump)
while abs(jump[j])<1 #jump[j]==0
jump[j]=4*rand(TDist(1),1)[1]
end
end
return jump
end
jump=a()
jump2=rand(TDist(1),10000)#nature t
jump4=rand(Normal(0,1),10000)#approximate Gaussian distribution
using Plots
histogram(jump,alpha=0.3,xlims=(-25,25),label="limited t",normalize=:probability,bins=10000)#,bins=10000 doesn't work
histogram!(jump2,alpha=0.8,label="nature t",normalize=:probability)
histogram!(jump4,alpha=0.5,label="Gaussian",normalize=:probability)
The bin width vary a lot, I’d like to make them dense and uniform, so found bincount in Gadfly. This start another disaster (In previous post people sove the undefined plot() problem by delete the package file and reinstall all…Are there any other solution available?
# using Gadfly #Caution: after using it, plot() became undefined
# plot(jump,bincount=10000,Geom.histogram)
using Plots
gr() #didn't make plot() recover
plot(jump)
(v1.2) pkg> add Plots #after this, still plot() not defined
(v1.2) pkg> build Plots #plot() not defined
I’m not sure I understand what the question is but I usually use StatsPlots.jl for histograms. There’s a bins keyword argument you can pass to histogram that will accept an integer or you can use one of the following auto-binning algorithms: :sturges, :sqrt, :rice, :scott or :fd. Here are some examples:
using Distributions
using StatsPlots
X = rand(Normal(), 100)
histogram(X, bins=5)
histogram(X, bins=10)
histogram(X, bins=:sturges)
Regarding the package not working after having installed Gadfly, I notice that you are working from the default environment (v1.2) pkg> so I would suggest setting up separate environments for each of your projects. For now, you might try to do pkg> rm Gadfly and then pkg> build Plots to remove Gadfly and then rebuild Plots to see if that helps.
pkg> rm Gadfly and then pkg> build Plots
are executed but still
julia> histogram(jump)
ERROR: UndefVarError: histogram not defined
Stacktrace:
[1] top-level scope at none:0
julia> plot(jump)
ERROR: UndefVarError: plot not defined
Stacktrace:
[1] top-level scope at none:0
I believe histogram is only exported by StatsPlots.jl so that wouldn’t work if you haven’t added StatsPlots. I think I know what the problem is. If Gadfly exports a plot function and you are loading both packages, you will need to specify which plot function you are calling like this Plots.plot(jump) or Gadfly.plot(jump). Try that.