From b3db49b4ae1b036fb08de6ca50b24c5907139b6e Mon Sep 17 00:00:00 2001 From: Jonathan Anderson Date: Tue, 18 Apr 2017 10:39:50 -0500 Subject: [PATCH 1/4] Update gr.jl in v0.6 so inline plots work MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I wanted to switch from using GR directly to using Plots, but the inline plots were not working for me. The following change is sufficient to generate inline plots in iterm for me. See the method in GR.jl: https://github.com/jheinen/GR.jl/blob/0f167b2be921a0014c405f760a1e1bc22b222751/src/GR.jl#L3014 julia> versioninfo() Julia Version 0.6.0-pre.beta.187 Commit 55c97fb* (2017-04-17 23:06 UTC) Platform Info: OS: Linux (x86_64-redhat-linux) CPU: Intel(R) Xeon(R) CPU E5-2670 v3 @ 2.30GHz WORD_SIZE: 64 BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell) LAPACK: libopenblas64_ LIBM: libopenlibm LLVM: libLLVM-3.9.1 (ORCJIT, haswell) julia> using TerminalExtensions julia> using Plots julia> gr(display_type=:inline); julia> z=[sin(sqrt(x^2+y^2)) for x in linspace(-2π,2π,50), y in linspace(-2π,2π,50)]; julia> contour(z) --- src/backends/gr.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index b092edd7..4fc31a90 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -1101,7 +1101,7 @@ function _display(plt::Plot{GRBackend}) ENV["GKS_FILEPATH"] = filepath gr_display(plt) GR.emergencyclosegks() - content = string("\033]1337;File=inline=1;preserveAspectRatio=0:", base64encode(open(readbytes, filepath)), "\a") + content = string("\033]1337;File=inline=1;preserveAspectRatio=0:", base64encode(open(read, filepath)), "\a") println(content) rm(filepath) else From 15739bc0ee8ef342b29f2351b59f5e308c988631 Mon Sep 17 00:00:00 2001 From: djsegal Date: Thu, 4 Oct 2018 17:20:14 -0400 Subject: [PATCH 2/4] Allow vectors of markers for pyplot scatter --- src/backends/pyplot.jl | 60 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index 92f33fd5..5ba5b086 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -603,6 +603,66 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) extrakw... )) end + push!(handles, handle) + elseif isa(series[:markershape], AbstractVector{Symbol}) + handle = [] + x,y = xyargs + shapes = series[:markershape] + + prev_marker = py_marker(_cycle(shapes,1)) + + cur_x_list = [] + cur_y_list = [] + + cur_color_list = [] + cur_scale_list = [] + + delete!(extrakw, :c) + + for i=1:length(y) + cur_marker = py_marker(_cycle(shapes,i)) + + push!(cur_x_list, _cycle(x,i)) + push!(cur_y_list, _cycle(y,i)) + + push!(cur_color_list, _cycle(markercolor, i)) + push!(cur_scale_list, py_thickness_scale(plt, _cycle(series[:markersize],i) .^ 2)) + + ( cur_marker == prev_marker ) && continue + + push!(handle, ax[:scatter](cur_x_list, cur_y_list; + label = series[:label], + zorder = series[:series_plotindex] + 0.5, + marker = prev_marker, + s = cur_scale_list, + edgecolors = py_markerstrokecolor(series), + linewidths = py_thickness_scale(plt, series[:markerstrokewidth]), + facecolors = cur_color_list, + extrakw... + )) + + cur_x_list = [] + cur_y_list = [] + + cur_color_list = [] + cur_scale_list = [] + + prev_marker = cur_marker + end + + if !isempty(cur_color_list) + push!(handle, ax[:scatter](cur_x_list, cur_y_list; + label = series[:label], + zorder = series[:series_plotindex] + 0.5, + marker = prev_marker, + s = cur_scale_list, + edgecolors = py_markerstrokecolor(series), + linewidths = py_thickness_scale(plt, series[:markerstrokewidth]), + facecolors = cur_color_list, + extrakw... + )) + end + push!(handles, handle) else # do a normal scatter plot From 268c2861c974cf666ff8ec65c04da80fdba5b9ee Mon Sep 17 00:00:00 2001 From: djsegal Date: Thu, 4 Oct 2018 17:29:37 -0400 Subject: [PATCH 3/4] Fix off-by-one error in pyplot scatter building --- src/backends/pyplot.jl | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index 5ba5b086..5c0f84f0 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -622,13 +622,15 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) for i=1:length(y) cur_marker = py_marker(_cycle(shapes,i)) - push!(cur_x_list, _cycle(x,i)) - push!(cur_y_list, _cycle(y,i)) + if ( cur_marker == prev_marker ) + push!(cur_x_list, _cycle(x,i)) + push!(cur_y_list, _cycle(y,i)) - push!(cur_color_list, _cycle(markercolor, i)) - push!(cur_scale_list, py_thickness_scale(plt, _cycle(series[:markersize],i) .^ 2)) + push!(cur_color_list, _cycle(markercolor, i)) + push!(cur_scale_list, py_thickness_scale(plt, _cycle(series[:markersize],i) .^ 2)) - ( cur_marker == prev_marker ) && continue + continue + end push!(handle, ax[:scatter](cur_x_list, cur_y_list; label = series[:label], @@ -641,11 +643,11 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series) extrakw... )) - cur_x_list = [] - cur_y_list = [] + cur_x_list = [_cycle(x,i)] + cur_y_list = [_cycle(y,i)] - cur_color_list = [] - cur_scale_list = [] + cur_color_list = [_cycle(markercolor, i)] + cur_scale_list = [py_thickness_scale(plt, _cycle(series[:markersize],i) .^ 2)] prev_marker = cur_marker end From c8c82811b3a2c20cfab5d92743fc209119e72bd4 Mon Sep 17 00:00:00 2001 From: djsegal Date: Tue, 22 Jan 2019 15:07:21 -0500 Subject: [PATCH 4/4] Fix bug where pyplot marker vec added blank legend --- src/backends/pyplot.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index 5c0f84f0..f13032dd 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -1330,12 +1330,12 @@ function py_add_legend(plt::Plot, sp::Subplot, ax) linewidth = py_thickness_scale(plt, clamp(get_linewidth(series), 0, 5)), linestyle = py_linestyle(series[:seriestype], get_linestyle(series)) ) - elseif series[:seriestype] in (:path, :straightline) + elseif series[:seriestype] in (:path, :straightline, :scatter) PyPlot.plt[:Line2D]((0,1),(0,0), color = py_color(get_linecolor(series), get_linealpha(series)), linewidth = py_thickness_scale(plt, clamp(get_linewidth(series), 0, 5)), linestyle = py_linestyle(:path, get_linestyle(series)), - marker = py_marker(series[:markershape]), + marker = py_marker(first(series[:markershape])), markeredgecolor = py_color(get_markerstrokecolor(series), get_markerstrokealpha(series)), markerfacecolor = series[:marker_z] == nothing ? py_color(get_markercolor(series), get_markeralpha(series)) : py_color(series[:markercolor][0.5]) )