如何绘制两个直方图之间的差异? (朱莉娅)

时间:2021-06-29 21:34:00

标签: julia histogram

前一段时间我在这里问了同样的问题,有人回答了我想要的! 使用 fit(histogram...)weights 你可以做到! (就像下图一样)。

julia> using StatsBase, Random; Random.seed!(0);

julia> x1, x2 = rand(100), rand(100);

julia> h1 = fit(Histogram, x1, 0:0.1:1);

julia> h2 = fit(Histogram, x2, 0:0.1:1);

julia> using Plots

julia> p1 = plot(h1, α=0.5, lab="x1") ; plot!(p1, h2, α=0.5, lab="x2")

julia> p2 = bar(0:0.1:1, h2.weights - h1.weights, lab="diff")

julia> plot(p1, p2)

问题是我不能使用 fit,我需要使用 Histogram(...)。而这个没有.weights。 我如何使用 Histogram 做到这一点? 这是我正在使用的:

using Plots
using StatsBase   
h1 = histogram(Group1, bins= B, normalize =:probability, labels = "Group 1")
h2 = histogram(Group2 , bins= B, normalize =:probability, labels ="Group 2"))

enter image description here

1 个答案:

答案 0 :(得分:3)

从技术上讲,任何常见的 Julia 包中都没有 const title = document.getElementById("title-block"); const removeSticky = new Waypoint({ element: flames, handler: function (direction) { if (direction === "down") { title.classList.add("unsticky"); } if (direction === "up") { title.classList.remove("unsticky"); } }, offset: 385, }); 函数;也许您的意思是 StatsBase 提供的 $(".from_date").datepicker({ minDate: 0, dateFormat: "dd/mm/y", defaultDate: "+1w", numberOfMonths: 1, onClose: function() { var minDate = $(this).datepicker('getDate'); var newMin = new Date(minDate.setDate(minDate.getDate() + 1)); $(".to_date").datepicker("option", "minDate", newMin); return $(".to_date").datepicker("show"); } }); $(".to_date").datepicker({ minDate: '+1D', dateFormat: "dd/mm/y", defaultDate: "+1w", numberOfMonths: 1 }); (大写 h)type,或者 Plots.jl 提供的 import xml.etree.ElementTree as ET import os path = "/your/original/XMLpath" #Source dstpath = "/your/newfiles/XMLpath" #save as XML in different folder for filename in os.listdir(path): if filename.endswith('.xml'): tree = ET.parse(path+"/"+filename) #full path of the XML file with it's name root = tree.getroot() for node in root.iter('name'): node.text = 'newname' save = dstpath+filename tree.write(save) (小写 h)函数?但无论哪种情况,答案都是“你不能”。

如果您的意思是 Plots.jl 中的 Histogram,那么遗憾的是没有实用的方法来访问该基础数据。另一方面,如果您的意思是来自 StatsBase 的 Histogram,则它仅适用于 histogram(它是一种类型,而不是可以单独使用的函数)。

还有其他直方图包,但如果出于任何原因您不能或不想使用 StatsBase 和 histogram,包括 FastHistograms.jlNaNStatistics.jl,这两者都比StatsBase 用于简单案例。所以,例如

Histogram

histogram diff example

相关问题