From fc54177029db9258b55ca102fd109b9b182e78d4 Mon Sep 17 00:00:00 2001 From: isentropic Date: Tue, 29 Sep 2020 14:26:58 +0900 Subject: [PATCH] text.usetex option hack pyplot (#2893) * text.usetex option hack * pyplot ticklabel fixes --- src/backends/pyplot.jl | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index 10e1bd51..651778eb 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -727,7 +727,15 @@ function py_set_lims(ax, sp::Subplot, axis::Axis) getproperty(ax, Symbol("set_", letter, "lim"))(lfrom, lto) end -py_surround_latextext(latexstring, env) = PyPlot.LaTeXStrings.latexstring(env, "{",latexstring[2:end-1],"}") +function py_surround_latextext(latexstring, env) + if latexstring[1] == '$' && latexstring[end] == '$' + unenclosed = latexstring[2:end-1] + else + unenclosed = latexstring + end + PyPlot.LaTeXStrings.latexstring(env, "{", unenclosed, "}") +end + function py_set_ticks(ax, ticks, letter, env) ticks == :auto && return @@ -746,7 +754,13 @@ function py_set_ticks(ax, ticks, letter, env) axis."set_ticks"(ticks) elseif ttype == :ticks_and_labels axis."set_ticks"(ticks[1]) - tick_labels = [py_surround_latextext(ticklabel, env) for ticklabel in ticks[2]] + + if pyrcparams["text.usetex"] + tick_labels = ticks[2] + else + tick_labels = [py_surround_latextext(ticklabel, env) for ticklabel in ticks[2]] + end + axis."set_ticklabels"(tick_labels) else error("Invalid input for $(letter)ticks: $ticks") @@ -1009,7 +1023,7 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend}) # Set ticks fontProperties = PyPlot.PyCall.PyDict(Dict("family" => axis[:tickfontfamily], "size" => py_thickness_scale(plt, axis[:tickfontsize]), - "useTex" => false, + # "useTex" => false, "rotation" => axis[:tickfontrotation])) getproperty(ax, Symbol("set_",letter,"ticklabels"))(getproperty(ax, Symbol("get_",letter,"ticks"))(), fontProperties) @@ -1019,8 +1033,11 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend}) # Tick marks intensity = 0.5 # This value corresponds to scaling of other grid elements - pyaxis."set_tick_params"(direction = axis[:tick_direction] == :out ? "out" : "in", width=py_thickness_scale(plt, intensity), - length= 5 * py_thickness_scale(plt, intensity)) + pyaxis."set_tick_params"( + direction = axis[:tick_direction] == :out ? "out" : "in", + width=py_thickness_scale(plt, intensity), + length= 5 * py_thickness_scale(plt, intensity) + ) getproperty(ax, Symbol("set_", letter, "label"))(axis[:guide]) if get(axis.plotattributes, :flip, false)