Plot 如何在Julia中绘制StatsBase.Histogram对象?
我在Julia中使用了一个包(Plot 如何在Julia中绘制StatsBase.Histogram对象?,plot,histogram,julia,Plot,Histogram,Julia,我在Julia中使用了一个包(LightGraphs.jl),它有一个预定义的直方图方法,可以创建网络的度分布g deg_hist = degree_histogram(g) 我想画一个情节,但我对朱莉娅的情节还不熟悉。返回的对象是一个StatsBase.Histogram,其内部字段如下: StatsBase.Histogram{Int64,1,Tuple{FloatRange{Float64}}} edges: 0.0:500.0:6000.0 weights: [79143,57,32,
LightGraphs.jl
),它有一个预定义的直方图方法,可以创建网络的度分布g
deg_hist = degree_histogram(g)
我想画一个情节,但我对朱莉娅的情节还不熟悉。返回的对象是一个StatsBase.Histogram
,其内部字段如下:
StatsBase.Histogram{Int64,1,Tuple{FloatRange{Float64}}}
edges: 0.0:500.0:6000.0
weights: [79143,57,32,17,13,4,4,3,3,2,1,1]
closed: right
你能帮助我如何利用这个对象来绘制直方图吗?使用直方图字段、边和权重来绘制直方图,例如
using PyPlot, StatsBase
a = rand(1000); # generate something to plot
test_hist = fit(Histogram, a)
# line plot
plot(test_hist.edges[1][2:end], test_hist.weights)
# bar plot
bar(0:length(test_hist.weights)-1, test_hist.weights)
xticks(0:length(test_hist.weights), test_hist.edges[1])
也可以创建/扩展绘图函数,添加如下方法:
function myplot(x::StatsBase.Histogram)
... # your code here
end
然后,您可以直接在直方图对象上调用绘图函数。我以为这已经实现了,但我刚刚将配方添加到StatPlot。如果您签出master,您将能够执行以下操作:
julia> using StatPlots, LightGraphs
julia> g = Graph(100,200);
julia> plot(degree_histogram(g))
作为参考,我添加到Statplot的相关配方:
@recipe function f(h::StatsBase.Histogram)
seriestype := :histogram
h.edges[1], h.weights
end
谢谢,我有一个关于StatPlots包的问题需要解决,但这似乎非常方便。