Skip to content

Commit

Permalink
Merge pull request #5 from fkguo/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
fkguo committed Jul 9, 2020
2 parents 2c546b3 + 874974b commit 1c5605e
Show file tree
Hide file tree
Showing 6 changed files with 973 additions and 485 deletions.
8 changes: 3 additions & 5 deletions Project.toml
Expand Up @@ -3,24 +3,22 @@ uuid = "beb75e20-2205-47e6-ad51-640e9c2309f1"
authors = ["Feng-Kun Guo"]
version = "0.1.0"


[deps]
PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
PyPlot = "d330b81b-6aea-500a-939a-2ce795aea3ee"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"


[compat]
PyCall = "1"
PyPlot = "1, 2"
Plots = "1"
julia = "1"
DataFrames = "0.21"
Combinatorics = "1"
ForwardDiff = "0.10"
# StatsBase = "0.33"
StatsBase = "0.31,0.32,0.33"


[extras]
Expand Down
702 changes: 477 additions & 225 deletions docs/.ipynb_checkpoints/example-checkpoint.ipynb

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions docs/Manifest.toml
Expand Up @@ -19,9 +19,9 @@ version = "0.8.2"

[[Documenter]]
deps = ["Base64", "Dates", "DocStringExtensions", "InteractiveUtils", "JSON", "LibGit2", "Logging", "Markdown", "REPL", "Test", "Unicode"]
git-tree-sha1 = "395fa1554c69735802bba37d9e7d9586fd44326c"
git-tree-sha1 = "f3464968c65fc78846dad1c038c474a2c39bbb23"
uuid = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
version = "0.24.11"
version = "0.25.0"

[[InteractiveUtils]]
deps = ["Markdown"]
Expand Down Expand Up @@ -52,9 +52,9 @@ uuid = "a63ad114-7e13-5084-954f-fe012c677804"

[[Parsers]]
deps = ["Dates", "Test"]
git-tree-sha1 = "eb3e09940c0d7ae01b01d9291ebad7b081c844d3"
git-tree-sha1 = "10134f2ee0b1978ae7752c41306e131a684e1f06"
uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0"
version = "1.0.5"
version = "1.0.7"

[[Pkg]]
deps = ["Dates", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"]
Expand Down
702 changes: 477 additions & 225 deletions docs/example.ipynb

Large diffs are not rendered by default.

36 changes: 11 additions & 25 deletions src/Data.jl
@@ -1,5 +1,5 @@
using DataFrames: DataFrame
using PyPlot: plt
using Plots: scatter, plot!

"""
Data(x::T, y::T, err::T) where {T<:Vector{Real}}
Expand All @@ -25,17 +25,12 @@ end
Data(df::DataFrame) = Data(df[:,1], df[:,2], df[:,3])

"""
plt_data(data::Data; xlab = "x", ylab = "y")
plt_data(data::Data; xlab = "x", ylab = "y", legend = :topleft)
Make a errorbar plot of the data
"""
function plt_data(data::Data; xlab = "x", ylab = "y")
fig, ax = plt.subplots(figsize = (6, 4))
ax.errorbar(data.x, data.y, data.err, fmt = "o", label = "Data" )
ax.legend()
ax.set_xlabel(xlab); ax.set_ylabel(ylab)
ax.minorticks_on(); ax.tick_params(which="both",direction="in", right="on", top="on")
ax.grid(which="major", axis="both", alpha=0.25)
function plt_data(data::Data; xlab = "x", ylab = "y", legend = :best)
scatter(data.x, data.y, yerror = data.err, label = "Data", xlab = xlab, ylab = ylab, legend = legend)
end


Expand Down Expand Up @@ -67,30 +62,21 @@ function chisq(dist::Function, data::Data, par::Tuple; fitrange = ())
end

"""
plt_best(dist::Function, fit::Fit, data::Data; xrange = (), xlab = "x", ylab = "y", npt = 100)`
plt_best(dist::Function, fit::Fit, data::Data; npts = 100, xrange = (), xlab = "x", ylab = "y", legend = :bes)`
for plotting the comparison of the result from fit with the data.
`xrange`: range of `x` for plotting the best fit; if not given then use the range of `data.x`
`npt`: number of points computed for the best-fit curve, default = 100.
`npts`: number of points computed for the best-fit curve, default = 100.
"""
function plt_best(dist::Function, fit::Fit, data::Data; xrange = (), xlab = "x", ylab = "y", npt = 100)
function plt_best(dist::Function, fit::Fit, data::Data; npts = 100, xrange = (), xlab = "x", ylab = "y", legend = :best)
paras1 = convert(Array, fit.args)

dis(x) = (length(func_argnames(dist)) > 2 ? dist(x, paras1...) : dist(x, paras1))

fig, ax = plt.subplots(figsize=(6,4))
ax.minorticks_on(); ax.tick_params(which="both",direction="in", right="on", top="on")
ax.set_xlabel(xlab)
ax.set_ylabel(ylab)

xrange = (isempty(xrange) && data.x)
wv = LinRange(xrange[1], xrange[end], npt)
ax.errorbar(data.x, data.y, data.err, c = "C0", fmt="o", label = "Data")
ax.plot(wv, dis.(wv), c = "C3", "-", label = "Best fit", lw=1.25)
ax.legend();

ax.set_xlim(wv[1], wv[end]); #ax.set_ylim(0, )
ax.grid(true, alpha = 0.3)
xrange = (isempty(xrange) ? data.x : xrange)
wv = LinRange(xrange[1], xrange[end], npts)
scatter(data.x, data.y, yerror = data.err, label = "Data", xlab = xlab, ylab = ylab, legend = legend)
plot!(wv, dis.(wv), label = "Best fit", lw=1.5)
end
2 changes: 1 addition & 1 deletion src/IMinuit.jl
@@ -1,7 +1,7 @@
__precompile__() # this module is safe to precompile
module IMinuit

using PyCall
using PyCall: PyObject, pycall, PyNULL, PyAny, pyimport_conda, pyimport
import PyCall: PyObject, pycall
import PyCall: hasproperty # Base.hasproperty in Julia 1.2
import Base: convert, ==, isequal, hash, haskey
Expand Down

0 comments on commit 1c5605e

Please sign in to comment.