remove const in pyplot
This commit is contained in:
parent
5132bebc7f
commit
60980f7f7f
@ -1,6 +1,3 @@
|
|||||||
# Do "using PyPlot: PyCall, LaTeXStrings" without dependency warning:
|
|
||||||
const PyCall = PyPlot.PyCall
|
|
||||||
const LaTeXStrings = PyPlot.LaTeXStrings
|
|
||||||
|
|
||||||
# https://github.com/stevengj/PyPlot.jl
|
# https://github.com/stevengj/PyPlot.jl
|
||||||
|
|
||||||
@ -35,7 +32,7 @@ else
|
|||||||
end
|
end
|
||||||
|
|
||||||
# PyCall API changes in v1.90.0
|
# PyCall API changes in v1.90.0
|
||||||
if !isdefined(PyCall, :_setproperty!)
|
if !isdefined(PyPlot.PyCall, :_setproperty!)
|
||||||
@warn "Plots no longer supports PyCall < 1.90.0 and PyPlot < 2.8.0. Either update PyCall and PyPlot or pin Plots to a version <= 0.23.2."
|
@warn "Plots no longer supports PyCall < 1.90.0 and PyPlot < 2.8.0. Either update PyCall and PyPlot or pin Plots to a version <= 0.23.2."
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -112,32 +109,6 @@ function py_marker(marker::Shape)
|
|||||||
pypath."Path"(mat)
|
pypath."Path"(mat)
|
||||||
end
|
end
|
||||||
|
|
||||||
const _path_MOVETO = UInt8(1)
|
|
||||||
const _path_LINETO = UInt8(2)
|
|
||||||
const _path_CLOSEPOLY = UInt8(79)
|
|
||||||
|
|
||||||
# # see http://matplotlib.org/users/path_tutorial.html
|
|
||||||
# # and http://matplotlib.org/api/path_api.html#matplotlib.path.Path
|
|
||||||
# function py_path(x, y)
|
|
||||||
# n = length(x)
|
|
||||||
# mat = zeros(n+1, 2)
|
|
||||||
# codes = zeros(UInt8, n+1)
|
|
||||||
# lastnan = true
|
|
||||||
# for i=1:n
|
|
||||||
# mat[i,1] = x[i]
|
|
||||||
# mat[i,2] = y[i]
|
|
||||||
# nan = !ok(x[i], y[i])
|
|
||||||
# codes[i] = if nan && i>1
|
|
||||||
# _path_CLOSEPOLY
|
|
||||||
# else
|
|
||||||
# lastnan ? _path_MOVETO : _path_LINETO
|
|
||||||
# end
|
|
||||||
# lastnan = nan
|
|
||||||
# end
|
|
||||||
# codes[n+1] = _path_CLOSEPOLY
|
|
||||||
# pypath["Path"](mat, codes)
|
|
||||||
# end
|
|
||||||
|
|
||||||
# get the marker shape
|
# get the marker shape
|
||||||
function py_marker(marker::Symbol)
|
function py_marker(marker::Symbol)
|
||||||
marker == :none && return " "
|
marker == :none && return " "
|
||||||
@ -204,11 +175,11 @@ end
|
|||||||
|
|
||||||
function labelfunc(scale::Symbol, backend::PyPlotBackend)
|
function labelfunc(scale::Symbol, backend::PyPlotBackend)
|
||||||
if scale == :log10
|
if scale == :log10
|
||||||
x -> LaTeXStrings.latexstring("10^{$x}")
|
x -> PyPlot.LaTeXStrings.latexstring("10^{$x}")
|
||||||
elseif scale == :log2
|
elseif scale == :log2
|
||||||
x -> LaTeXStrings.latexstring("2^{$x}")
|
x -> PyPlot.LaTeXStrings.latexstring("2^{$x}")
|
||||||
elseif scale == :ln
|
elseif scale == :ln
|
||||||
x -> LaTeXStrings.latexstring("e^{$x}")
|
x -> PyPlot.LaTeXStrings.latexstring("e^{$x}")
|
||||||
else
|
else
|
||||||
string
|
string
|
||||||
end
|
end
|
||||||
@ -216,7 +187,7 @@ end
|
|||||||
|
|
||||||
function py_mask_nans(z)
|
function py_mask_nans(z)
|
||||||
# pynp["ma"][:masked_invalid](z)))
|
# pynp["ma"][:masked_invalid](z)))
|
||||||
PyCall.pycall(pynp."ma"."masked_invalid", Any, z)
|
PyPlot.PyCall.pycall(pynp."ma"."masked_invalid", Any, z)
|
||||||
# pynp["ma"][:masked_where](pynp["isnan"](z),z)
|
# pynp["ma"][:masked_where](pynp["isnan"](z),z)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -944,7 +915,7 @@ function py_set_axis_colors(sp, ax, a::Axis)
|
|||||||
spine."set_color"(py_color(a[:foreground_color_border]))
|
spine."set_color"(py_color(a[:foreground_color_border]))
|
||||||
end
|
end
|
||||||
axissym = Symbol(a[:letter], :axis)
|
axissym = Symbol(a[:letter], :axis)
|
||||||
if PyCall.hasproperty(ax, axissym)
|
if PyPlot.PyCall.hasproperty(ax, axissym)
|
||||||
tickcolor = sp[:framestyle] in (:zerolines, :grid) ? py_color(plot_color(a[:foreground_color_grid], a[:gridalpha])) : py_color(a[:foreground_color_axis])
|
tickcolor = sp[:framestyle] in (:zerolines, :grid) ? py_color(plot_color(a[:foreground_color_grid], a[:gridalpha])) : py_color(a[:foreground_color_axis])
|
||||||
ax."tick_params"(axis=string(a[:letter]), which="both",
|
ax."tick_params"(axis=string(a[:letter]), which="both",
|
||||||
colors=tickcolor,
|
colors=tickcolor,
|
||||||
@ -1085,7 +1056,7 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend})
|
|||||||
# axis attributes
|
# axis attributes
|
||||||
for letter in (:x, :y, :z)
|
for letter in (:x, :y, :z)
|
||||||
axissym = Symbol(letter, :axis)
|
axissym = Symbol(letter, :axis)
|
||||||
PyCall.hasproperty(ax, axissym) || continue
|
PyPlot.PyCall.hasproperty(ax, axissym) || continue
|
||||||
axis = sp[axissym]
|
axis = sp[axissym]
|
||||||
pyaxis = getproperty(ax, axissym)
|
pyaxis = getproperty(ax, axissym)
|
||||||
if axis[:mirror] && letter != :z
|
if axis[:mirror] && letter != :z
|
||||||
@ -1293,43 +1264,44 @@ end
|
|||||||
|
|
||||||
# -----------------------------------------------------------------
|
# -----------------------------------------------------------------
|
||||||
|
|
||||||
const _pyplot_legend_pos = KW(
|
py_legend_pos(pos::Symbol) = get(
|
||||||
:right => "right",
|
(
|
||||||
:left => "center left",
|
right = "right",
|
||||||
:top => "upper center",
|
left = "center left",
|
||||||
:bottom => "lower center",
|
top = "upper center",
|
||||||
:bottomleft => "lower left",
|
bottom = "lower center",
|
||||||
:bottomright => "lower right",
|
bottomleft = "lower left",
|
||||||
:topright => "upper right",
|
bottomright = "lower right",
|
||||||
:topleft => "upper left"
|
topright = "upper right",
|
||||||
)
|
topleft = "upper left",
|
||||||
|
outerright = "center left",
|
||||||
const _pyplot_legend_pos_outer = KW(
|
outerleft = "right",
|
||||||
:outerright => "center left",
|
outertop = "lower center",
|
||||||
:outerleft => "right",
|
outerbottom = "upper center",
|
||||||
:outertop => "lower center",
|
outerbottomleft = "lower right",
|
||||||
:outerbottom => "upper center",
|
outerbottomright = "lower left",
|
||||||
:outerbottomleft => "lower right",
|
outertopright = "upper left",
|
||||||
:outerbottomright => "lower left",
|
outertopleft = "upper right",
|
||||||
:outertopright => "upper left",
|
),
|
||||||
:outertopleft => "upper right"
|
pos,
|
||||||
|
"best",
|
||||||
)
|
)
|
||||||
|
|
||||||
py_legend_pos(pos::Symbol) = get(_pyplot_legend_pos, pos, get(_pyplot_legend_pos_outer, pos, "best"))
|
|
||||||
py_legend_pos(pos) = "lower left"
|
py_legend_pos(pos) = "lower left"
|
||||||
|
|
||||||
const _pyplot_legend_bbox_outer = KW(
|
py_legend_bbox(pos::Symbol) = get(
|
||||||
:outerright => (1.0, 0.5, 0.0, 0.0),
|
(
|
||||||
:outerleft => (-0.15, 0.5, 0.0, 0.0),
|
outerright = (1.0, 0.5, 0.0, 0.0),
|
||||||
:outertop => (0.5, 1.0, 0.0, 0.0),
|
outerleft = (-0.15, 0.5, 0.0, 0.0),
|
||||||
:outerbottom => (0.5, -0.15, 0.0, 0.0),
|
outertop = (0.5, 1.0, 0.0, 0.0),
|
||||||
:outerbottomleft => (-0.15, 0.0, 0.0, 0.0),
|
outerbottom = (0.5, -0.15, 0.0, 0.0),
|
||||||
:outerbottomright => (1.0, 0.0, 0.0, 0.0),
|
outerbottomleft = (-0.15, 0.0, 0.0, 0.0),
|
||||||
:outertopright => (1.0, 1.0, 0.0, 0.0),
|
outerbottomright = (1.0, 0.0, 0.0, 0.0),
|
||||||
:outertopleft => (-0.15, 1.0, 0.0, 0.0)
|
outertopright = (1.0, 1.0, 0.0, 0.0),
|
||||||
|
outertopleft = (-0.15, 1.0, 0.0, 0.0),
|
||||||
|
),
|
||||||
|
pos,
|
||||||
|
(0.0, 0.0, 1.0, 1.0),
|
||||||
)
|
)
|
||||||
|
|
||||||
py_legend_bbox(pos::Symbol) = get(_pyplot_legend_bbox_outer, pos, (0.0, 0.0, 1.0, 1.0))
|
|
||||||
py_legend_bbox(pos) = pos
|
py_legend_bbox(pos) = pos
|
||||||
|
|
||||||
function py_add_legend(plt::Plot, sp::Subplot, ax)
|
function py_add_legend(plt::Plot, sp::Subplot, ax)
|
||||||
@ -1431,8 +1403,7 @@ end
|
|||||||
_display(plt::Plot{PyPlotBackend}) = plt.o."show"()
|
_display(plt::Plot{PyPlotBackend}) = plt.o."show"()
|
||||||
|
|
||||||
|
|
||||||
|
for (mime, fmt) in (
|
||||||
const _pyplot_mimeformats = Dict(
|
|
||||||
"application/eps" => "eps",
|
"application/eps" => "eps",
|
||||||
"image/eps" => "eps",
|
"image/eps" => "eps",
|
||||||
"application/pdf" => "pdf",
|
"application/pdf" => "pdf",
|
||||||
@ -1441,9 +1412,6 @@ const _pyplot_mimeformats = Dict(
|
|||||||
"image/svg+xml" => "svg",
|
"image/svg+xml" => "svg",
|
||||||
"application/x-tex" => "pgf"
|
"application/x-tex" => "pgf"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
for (mime, fmt) in _pyplot_mimeformats
|
|
||||||
@eval function _show(io::IO, ::MIME{Symbol($mime)}, plt::Plot{PyPlotBackend})
|
@eval function _show(io::IO, ::MIME{Symbol($mime)}, plt::Plot{PyPlotBackend})
|
||||||
fig = plt.o
|
fig = plt.o
|
||||||
fig."canvas"."print_figure"(
|
fig."canvas"."print_figure"(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user