added qwt hline/vline; working on setTicksFromStringVector
This commit is contained in:
parent
06ab514472
commit
f284857438
@ -2,42 +2,39 @@
|
|||||||
"cells": [
|
"cells": [
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 4,
|
"execution_count": 1,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"collapsed": false
|
"collapsed": false
|
||||||
},
|
},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"name": "stdout",
|
"name": "stderr",
|
||||||
"output_type": "stream",
|
"output_type": "stream",
|
||||||
"text": [
|
"text": [
|
||||||
"[Plots.jl] Switched to backend: gadfly"
|
"INFO: Recompiling stale cache file /home/tom/.julia/lib/v0.4/Plots.ji for module Plots.\n"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ename": "MethodError",
|
"name": "stdout",
|
||||||
"evalue": "MethodError: `isless` has no method matching isless(::ASCIIString, ::Int64)\nClosest candidates are:\n isless(!Matched::AbstractFloat, ::Real)\n isless(!Matched::Real, ::Real)\n isless(!Matched::Char, ::Integer)\n ...",
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"[Plots.jl] Default backend: immerse\n",
|
||||||
|
"[Plots.jl] Switched to backend: gadfly\n",
|
||||||
|
"[Plots.jl] Initializing backend: gadfly\n",
|
||||||
|
"v = Union{ASCIIString,UTF8String}[\"x01\",\"x01\",\"x01\",\"x01\",\"x01\",\"x01\",\"x01\",\"x01\",\"x02\",\"x02\",\"x02\",\"x02\",\"x02\",\"x02\",\"x02\",\"x02\",\"x02\",\"x02\",\"x02\",\"x03\",\"x03\",\"x03\",\"x03\",\"x03\",\"x03\",\"x03\",\"x03\",\"x03\",\"x04\",\"x04\",\"x04\",\"x04\",\"x04\",\"x04\",\"x04\",\"x05\",\"x05\",\"x05\",\"x05\",\"x05\",\"x05\",\"x05\",\"x05\",\"x05\",\"x05\",\"x05\",\"x06\",\"x06\",\"x06\",\"x06\",\"x06\",\"x06\",\"x06\",\"x06\",\"x06\",\"x06\",\"x06\",\"x06\",\"x07\",\"x07\",\"x07\",\"x07\",\"x07\",\"x07\",\"x07\",\"x07\",\"x07\",\"x07\",\"x08\",\"x08\",\"x08\",\"x08\",\"x08\",\"x08\",\"x08\",\"x08\",\"x08\",\"x08\",\"x08\",\"x08\",\"x08\",\"x08\",\"x09\",\"x09\",\"x09\",\"x09\",\"x09\",\"x09\",\"x09\",\"x09\",\"x10\",\"x10\",\"x10\",\"x10\",\"x10\",\"x10\",\"x10\",\"x10\",\"x10\",\"x10\"]"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ename": "LoadError",
|
||||||
|
"evalue": "LoadError: KeyError: xticks not found\nwhile loading In[1], in expression starting on line 6",
|
||||||
"output_type": "error",
|
"output_type": "error",
|
||||||
"traceback": [
|
"traceback": [
|
||||||
"MethodError: `isless` has no method matching isless(::ASCIIString, ::Int64)\nClosest candidates are:\n isless(!Matched::AbstractFloat, ::Real)\n isless(!Matched::Real, ::Real)\n isless(!Matched::Char, ::Integer)\n ...",
|
"LoadError: KeyError: xticks not found\nwhile loading In[1], in expression starting on line 6",
|
||||||
"",
|
"",
|
||||||
" in min at operators.jl:58",
|
" in setTicksFromStringVector at /home/tom/.julia/v0.4/Plots/src/plot.jl:138",
|
||||||
" in apply_statistic at /home/tom/.julia/v0.4/Gadfly/src/statistics.jl:818",
|
" in plot! at /home/tom/.julia/v0.4/Plots/src/plot.jl:104",
|
||||||
" in apply_statistics at /home/tom/.julia/v0.4/Gadfly/src/statistics.jl:38",
|
" in plot at /home/tom/.julia/v0.4/Plots/src/plot.jl:58",
|
||||||
" in render_prepare at /home/tom/.julia/v0.4/Gadfly/src/Gadfly.jl:676",
|
" in scatter at /home/tom/.julia/v0.4/Plots/src/Plots.jl:81"
|
||||||
" in render at /home/tom/.julia/v0.4/Gadfly/src/Gadfly.jl:717",
|
|
||||||
" in draw at /home/tom/.julia/v0.4/Gadfly/src/Gadfly.jl:821",
|
|
||||||
" in writemime at /home/tom/.julia/v0.4/Plots/src/backends/gadfly.jl:352",
|
|
||||||
" in base64encode at base64.jl:160",
|
|
||||||
" in display_dict at /home/tom/.julia/v0.4/IJulia/src/execute_request.jl:32"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "stdout",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"\n",
|
|
||||||
"ticks = Union{ASCIIString,UTF8String}[\"x01\",\"x02\",\"x03\",\"x04\",\"x05\",\"x06\",\"x07\",\"x08\",\"x09\",\"x10\"]\n"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
@ -47,7 +44,7 @@
|
|||||||
"xstr = [@sprintf(\"x%02d\",i) for i in 1:10]\n",
|
"xstr = [@sprintf(\"x%02d\",i) for i in 1:10]\n",
|
||||||
"x = sort(sample(xstr, 100))\n",
|
"x = sort(sample(xstr, 100))\n",
|
||||||
"y = rand(length(x))\n",
|
"y = rand(length(x))\n",
|
||||||
"scatter(x,y)"
|
"scatter(x,y)\n"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@ -48,7 +48,7 @@ supportedArgs(::QwtPackage) = [
|
|||||||
:yrightlabel,
|
:yrightlabel,
|
||||||
# :yticks,
|
# :yticks,
|
||||||
]
|
]
|
||||||
supportedTypes(::QwtPackage) = [:none, :line, :path, :steppre, :steppost, :sticks, :scatter, :heatmap, :hexbin, :hist, :bar]
|
supportedTypes(::QwtPackage) = [:none, :line, :path, :steppre, :steppost, :sticks, :scatter, :heatmap, :hexbin, :hist, :bar, :hline, :vline]
|
||||||
supportedMarkers(::QwtPackage) = [:none, :auto, :rect, :ellipse, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star1, :star2, :hexagon]
|
supportedMarkers(::QwtPackage) = [:none, :auto, :rect, :ellipse, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star1, :star2, :hexagon]
|
||||||
|
|
||||||
# -------------------------------
|
# -------------------------------
|
||||||
@ -67,16 +67,27 @@ function replaceLinetypeAlias(d)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function adjustQwtKeywords(iscreating::Bool; kw...)
|
function adjustQwtKeywords(plt::Plot{QwtPackage}, iscreating::Bool; kw...)
|
||||||
d = Dict(kw)
|
d = Dict(kw)
|
||||||
if d[:linetype] == :scatter
|
lt = d[:linetype]
|
||||||
|
if lt == :scatter
|
||||||
d[:linetype] = :none
|
d[:linetype] = :none
|
||||||
if d[:marker] == :none
|
if d[:marker] == :none
|
||||||
d[:marker] = :ellipse
|
d[:marker] = :ellipse
|
||||||
end
|
end
|
||||||
elseif !iscreating && d[:linetype] == :bar
|
|
||||||
|
elseif lt in (:hline, :vline)
|
||||||
|
addLineMarker(plt, d)
|
||||||
|
d[:linetype] = :none
|
||||||
|
d[:marker] = :ellipse
|
||||||
|
d[:markersize] = 1
|
||||||
|
if lt == :vline
|
||||||
|
d[:x], d[:y] = d[:y], d[:x]
|
||||||
|
end
|
||||||
|
|
||||||
|
elseif !iscreating && lt == :bar
|
||||||
d = barHack(; kw...)
|
d = barHack(; kw...)
|
||||||
elseif !iscreating && d[:linetype] == :hist
|
elseif !iscreating && lt == :hist
|
||||||
d = barHack(; histogramHack(; kw...)...)
|
d = barHack(; histogramHack(; kw...)...)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -92,7 +103,7 @@ function plot(pkg::QwtPackage; kw...)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function plot!(::QwtPackage, plt::Plot; kw...)
|
function plot!(::QwtPackage, plt::Plot; kw...)
|
||||||
d = adjustQwtKeywords(false; kw...)
|
d = adjustQwtKeywords(plt, false; kw...)
|
||||||
Qwt.oplot(plt.o; d...)
|
Qwt.oplot(plt.o; d...)
|
||||||
push!(plt.seriesargs, d)
|
push!(plt.seriesargs, d)
|
||||||
plt
|
plt
|
||||||
@ -107,6 +118,23 @@ end
|
|||||||
|
|
||||||
# ----------------------------------------------------------------
|
# ----------------------------------------------------------------
|
||||||
|
|
||||||
|
# curve.setPen(Qt.QPen(Qt.QColor(color), width, self.getLineStyle(linestyle)))
|
||||||
|
function addLineMarker(plt::Plot{QwtPackage}, d::Dict)
|
||||||
|
for yi in d[:y]
|
||||||
|
marker = Qwt.QWT.QwtPlotMarker()
|
||||||
|
ishorizontal = (d[:linetype] == :hline)
|
||||||
|
marker[:setLineStyle](ishorizontal ? 1 : 2)
|
||||||
|
marker[ishorizontal ? :setYValue : :setXValue](yi)
|
||||||
|
qcolor = Qwt.convertRGBToQColor(d[:color])
|
||||||
|
linestyle = plt.o.widget[:getLineStyle](string(d[:linestyle]))
|
||||||
|
marker[:setLinePen](Qwt.QT.QPen(qcolor, d[:width], linestyle))
|
||||||
|
marker[:attach](plt.o.widget)
|
||||||
|
end
|
||||||
|
|
||||||
|
# marker[:setValue](x, y)
|
||||||
|
# marker[:setLabel](Qwt.QWT.QwtText(val))
|
||||||
|
# marker[:attach](plt.o.widget)
|
||||||
|
end
|
||||||
|
|
||||||
function createQwtAnnotation(plt::Plot, x, y, val::AbstractString)
|
function createQwtAnnotation(plt::Plot, x, y, val::AbstractString)
|
||||||
marker = Qwt.QWT.QwtPlotMarker()
|
marker = Qwt.QWT.QwtPlotMarker()
|
||||||
|
|||||||
28
src/plot.jl
28
src/plot.jl
@ -59,11 +59,6 @@ function plot(args...; kw...)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
# function plot_display(args...; kw...)
|
|
||||||
# plt = plot(args...; kw...)
|
|
||||||
# display(plt)
|
|
||||||
# plt
|
|
||||||
# end
|
|
||||||
|
|
||||||
# this adds to the current plot
|
# this adds to the current plot
|
||||||
function plot!(args...; kw...)
|
function plot!(args...; kw...)
|
||||||
@ -109,6 +104,8 @@ function plot!(plt::Plot, args...; kw...)
|
|||||||
setTicksFromStringVector(d, di, :x, :xticks)
|
setTicksFromStringVector(d, di, :x, :xticks)
|
||||||
setTicksFromStringVector(d, di, :y, :yticks)
|
setTicksFromStringVector(d, di, :y, :yticks)
|
||||||
|
|
||||||
|
@show di[:x] di[:y]
|
||||||
|
|
||||||
# println("Plotting: ", di)
|
# println("Plotting: ", di)
|
||||||
plot!(plt.backend, plt; di...)
|
plot!(plt.backend, plt; di...)
|
||||||
|
|
||||||
@ -116,6 +113,8 @@ function plot!(plt::Plot, args...; kw...)
|
|||||||
|
|
||||||
addAnnotations(plt, d)
|
addAnnotations(plt, d)
|
||||||
|
|
||||||
|
# @show d[:xticks] d[:yticks]
|
||||||
|
|
||||||
# add title, axis labels, ticks, etc
|
# add title, axis labels, ticks, etc
|
||||||
updatePlotItems(plt, d)
|
updatePlotItems(plt, d)
|
||||||
current(plt)
|
current(plt)
|
||||||
@ -135,11 +134,26 @@ function setTicksFromStringVector(d::Dict, di::Dict, sym::Symbol, ticksym::Symbo
|
|||||||
# if the x or y values are strings, set ticks to the unique values, and x/y to the indices of the ticks
|
# if the x or y values are strings, set ticks to the unique values, and x/y to the indices of the ticks
|
||||||
# @show get(d,ticksym,:auto) == :auto isa(di[sym], AbstractArray) isa(eltype(di[sym]), AbstractString)
|
# @show get(d,ticksym,:auto) == :auto isa(di[sym], AbstractArray) isa(eltype(di[sym]), AbstractString)
|
||||||
# @show get(d,ticksym,:auto) eltype(di[sym])
|
# @show get(d,ticksym,:auto) eltype(di[sym])
|
||||||
if get(d,ticksym,:auto) == :auto && isa(di[sym], AbstractArray) && issubtype(eltype(di[sym]), AbstractString)
|
|
||||||
|
haskey(d, ticksym) || return
|
||||||
|
d[ticksym] == :auto || return
|
||||||
|
|
||||||
|
v = di[sym]
|
||||||
|
@show v
|
||||||
|
isa(v, AbstractArray) || return
|
||||||
|
|
||||||
|
T = eltype(v)
|
||||||
|
@show T
|
||||||
|
if T <: AbstractString || all(x -> x <: AbstractString, T.types)
|
||||||
|
|
||||||
|
# if get(d,ticksym,:auto) == :auto && isa(di[sym], AbstractArray) &&
|
||||||
|
# (issubtype(eltype(di[sym]), AbstractString) || all(x->x<:AbstractString, eltype(di[sym]).types))
|
||||||
|
@show sym ticksym di[sym] d[ticksym]
|
||||||
|
|
||||||
ticks = unique(di[sym])
|
ticks = unique(di[sym])
|
||||||
@show ticks
|
@show ticks
|
||||||
di[sym] = Int[findnext(ticks, v, 1) for v in di[sym]]
|
di[sym] = Int[findnext(ticks, v, 1) for v in di[sym]]
|
||||||
d[ticksym] = ticks
|
d[ticksym] = UTF8String[t for t in ticks]
|
||||||
end
|
end
|
||||||
# @show sym ticksym di[sym] d[ticksym]
|
# @show sym ticksym di[sym] d[ticksym]
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user