【发布时间】:2017-01-09 10:24:58
【问题描述】:
参考这个链接Displaying 3 histograms on 1 axis in a legible way - matplotlib在python的1个轴上显示3个直方图,我尝试在julia中做同样的事情,但dic函数无法识别。
这里是 julia 的代码。函数 dict 无法识别。
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()
我尝试使用 : plotly 并且我也遇到了一些问题。这是使用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)
【问题讨论】:
标签: matplotlib histogram julia plotly