GR.jl
GR.jl copied to clipboard
posted example: Using windows and viewports doesn't behave as expected
Snappy plots for Julia! However when walking through example Using windows and viewports I don't see anything on the screen. Does the example posted on the GR web page work for others or is it outdated?
I am trying to use GR.drawarc(...) but nothing happened, so I tried the posted example -- same: no actual output. All the official plot commands do as advertised though -- with the exception of low level calls -- what could be wrong?
update: I checked the python version of the tutorial, same error: GKS: Dimensions of image are invalid in routine DRAW_IMAGE
no output other than a blank window popping up. Probably something is wrong -- then again, all the julia plot commands work -- hmmm...
ubuntu 20.04 GR.version: "0.53.0"
julia> versioninfo()
Julia Version 1.5.3
Commit 788b2c77c1 (2020-11-09 13:37 UTC)
Platform Info:
OS: Linux (x86_64-linux-gnu)
CPU: Intel(R) Core(TM) i7-8665U CPU @ 1.90GHz
WORD_SIZE: 64
LIBM: libimf
LLVM: libLLVM-9.0.1 (ORCJIT, skylake)
Environment:
JULIA_HDF5_PATH = /usr/local/
JULIA_MPI_LIBRARY = libmpi
JULIA_LOAD_PATH = @:@v#.#:@stdlib:/home/steven/.julia:/usr/local/share/julia-depot/environments/globalenv
JULIA_MPI_BINARY = system
JULIA_MPIEXEC = srun
JULIA_DEPOT_PATH = /home/steven/.julia:/usr/local/share/julia-depot
JULIA_MPI_ABI = OpenMPI
JULIA_MPI_PATH = /usr/local
JULIA_PROJECT = /opt/projects/analytics
You will have to call updatews()
after you call low-level functions.
Thanks a lot! Would I be too pushy if I asked here how to rotate an arc
? So far everything checked out I was able to add arc(...)
to GRUtils
it performs as advertised; now I would like to rotate the arc around its centre -- is this possible? Is there a forum where would be more appropriate to ask these questions?
Could you please provide your arc
example - there are several ways to draw arcs with GR?
I abandoned the arc
for now, instead proceeded with bezier curve approximation of ellipse based on Drawing an elliptical arc using polylines, quadratic or cubic Bézier curves by L. Maisonobe
where the ellipse composed of 4 segments of bezier curves.
As per discussion on gitter where @jheinen suggested to use the following snippet:
function rotate(x, y, angle)
θ = angle * π / 180
x .* cos(θ) - y .* sin(θ), x .* sin(θ) + y .* cos(θ)
end
function drawellipse(x, y, angle, a, b)
p = [ 0 1 0.5523 1 1 0.5523 1 0 1 -0.5523 0.5523 -1 0 -1 -0.5523 -1 -1 -0.5523 -1 0 -1 0.5523 -0.5523 1 0 1 ]
Δx, Δy = rotate(p[1:2:end] .* a, p[2:2:end] .* b, angle)
path(x .+ Δx, y .+ Δy, "MCCCCf")
end
So far I added features to control attributes for
- centre point:
markersize
,markertype
- elliptic curve:
linewidth
,linecolor
- semi axes:
linewidth
,linecolor
,linetype
not yet implemented:
- labels:
a,b
x,y
angle
example syntax is aimed to fit into GRUtils.jl
ecosystem to draw an ellipse with points i,j
and major and minor axes a,b
centered at x,y
:
fg = ellipse( x, y, angle_in_degrees, a, b,
markertype=GR.MARKERTYPE_DIAGONAL_CROSS, markersize=3,
linewidth=2.6, linetype=GR.LINETYPE_DOUBLE_DOT, xlabel="xlabel",
ylabel="ylabel", xlim=(-0.0, 1.2), ylim=(0.0, 1.2))
and here is the most recent sketch of the ellipse
geometry:
function draw(g::Geometry, ::Val{:ellipse})::Nothing
GR.savestate()
# centre of the ellipse - not the focii
GR.setmarkersize(float(get(g.attributes, :markersize, 1.0)))
GR.setmarkertype(Int(get(g.attributes, :markertype, GR.MARKERTYPE_DOT)))
w = float(get(g.attributes, :linewidth, 1.0))
GR.setborderwidth(w) # bezier curve uses this
GR.setlinewidth(w) # semi axes are lines
# semi axes
GR.setlinetype(Int(get(g.attributes, :linetype, GR.LINETYPE_DOTTED)))
color_index = 1 # default colorindex is fg color
if haskey(g.attributes, :linecolor) # optionally you can set the color similarly to `line`
color_index = colorindex(Int(g.attributes[:linecolor])); end
GR.setbordercolorind(color_index) # for cubic bezier curves
GR.setlinecolorind(color_index) # and this is for the semi axes a,b
x,y, angle, a, b = g.x[1], g.x[2], g.x[3], g.x[4], g.x[5]
θ = angle * π / 180
# constant 0.55228474 = 4.0*tan(π/8)/3.0 = 4.0*tan(π/8)/3.
p = [ 0 1 0.55228474 1 1 0.55228474 1 0 1 -0.55228474 0.55228474 -1 0 -1 -0.55228474 -1 -1 -0.55228474 -1 0 -1 0.55228474 -0.55228474 1 0 1 ]
Δx, Δy = rotate_ellipse_(p[1:2:end] .* a, p[2:2:end] .* b, θ)
GR.path(x .+ Δx, y .+ Δy, "MCCCCs")
# plotting semi axes a,b:
p = [0 0 0 1 0 0 1 0]
Δx, Δy = rotate_ellipse_(p[1:2:end] .* a, p[2:2:end] .* b, θ)
GR.setborderwidth(0.3w)
GR.setlinewidth(0.3w)
GR.polyline(x .+ Δx, y .+ Δy)
# center point
GR.polymarker([x], [y])
GR.restorestate()
return nothing
end