參考此鏈接Displaying 3 histograms on 1 axis in a legible way - matplotlib在python中的1軸上顯示3個直方圖,我試圖在茱莉亞做同樣的事情,但是不能識別dic函數。在1軸上顯示5個直方圖 - julia
這裏是茱莉亞的代碼。函數字典不被識別。
using PyCall
@pyimport matplotlib.pyplot as plt
a=vec(rand(1:1000,400,300))
b = vec(rand(200:700,400,300))
c = vec(rand(300:1200,400,300))
common_params = dict(bins=20,
range=(-5, 5),
normed="True")
plt.subplots_adjust(hspace=.4)
plt.subplot(311)
plt.title('Default')
plt.hist(a, **common_params)
plt.hist(b, **common_params)
plt.hist(c, **common_params)
plt.subplot(312)
plt.title('Skinny shift - 3 at a time')
plt.hist((a, b, c), **common_params)
plt.subplot(313)
common_params['histtype'] = 'step'
plt.title('With steps')
plt.hist(a, **common_params)
plt.hist(b, **common_params)
plt.hist(c, **common_params)
plt.savefig('3hist.png')
plt.show()
l試圖使用:情節和我也面臨一些問題。下面是使用plotly
using Plotly
x0 = randn(500)
x1 = randn(500)+1
trace1 = [
"x" => x0,
"type" => "histogram"
]
trace2 = [
"x" => x1,
"type" => "histogram"
]
data = [trace1, trace2]
layout = ["barmode" => "stack"]
response = Plotly.plot(data, ["layout" => layout, "filename" => "stacked-histogram", "fileopt" => "overwrite"])
plot_url = response["url"]
返回的錯誤代碼是:
WARNING: deprecated syntax "[a=>b, ...]" at /home/anelmad/Desktop/stage-inria/code/HTreeRBM.jl/my_tree/random_data/graph_try.jl:20.
Use "Dict(a=>b, ...)" instead.
ERROR: LoadError: MethodError: `convert` has no method matching convert(::Type{PlotlyJS.Plot{TT<:PlotlyJS.AbstractTrace}}, ::Array{Dict{ASCIIString,Any},1}, ::Dict{ASCIIString,Any})
This may have arisen from a call to the constructor PlotlyJS.Plot{TT<:PlotlyJS.AbstractTrace}(...),
since type constructors fall back to convert methods.
Closest candidates are:
PlotlyJS.Plot{T<:PlotlyJS.AbstractTrace}(::Array{T<:PlotlyJS.AbstractTrace,1}, ::Any)
PlotlyJS.Plot(::PlotlyJS.AbstractTrace, ::Any)
call{T}(::Type{T}, ::Any)