From 9edc6f590ae7ea72825155896ccbd6a5ed3c211f Mon Sep 17 00:00:00 2001 From: zhanibek Date: Tue, 11 Aug 2020 15:41:50 +0900 Subject: [PATCH] pyplot ticklabel fixes --- src/backends/pyplot.jl | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index db6e2efe..dd3d7175 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -842,7 +842,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 @@ -861,11 +869,13 @@ function py_set_ticks(ax, ticks, letter, env) axis."set_ticks"(ticks) elseif ttype == :ticks_and_labels axis."set_ticks"(ticks[1]) + 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")