commit
20bd9d6160
@ -70,18 +70,18 @@ function _initialize_backend(::PyPlotBackend)
|
|||||||
append!(Base.Multimedia.displays, otherdisplays)
|
append!(Base.Multimedia.displays, otherdisplays)
|
||||||
|
|
||||||
export PyPlot
|
export PyPlot
|
||||||
const pycolors = PyPlot.pywrap(PyPlot.pyimport("matplotlib.colors"))
|
const pycolors = PyPlot.pyimport("matplotlib.colors")
|
||||||
const pypath = PyPlot.pywrap(PyPlot.pyimport("matplotlib.path"))
|
const pypath = PyPlot.pyimport("matplotlib.path")
|
||||||
const mplot3d = PyPlot.pywrap(PyPlot.pyimport("mpl_toolkits.mplot3d"))
|
const mplot3d = PyPlot.pyimport("mpl_toolkits.mplot3d")
|
||||||
const pypatches = PyPlot.pywrap(PyPlot.pyimport("matplotlib.patches"))
|
const pypatches = PyPlot.pyimport("matplotlib.patches")
|
||||||
const pyfont = PyPlot.pywrap(PyPlot.pyimport("matplotlib.font_manager"))
|
const pyfont = PyPlot.pyimport("matplotlib.font_manager")
|
||||||
const pyticker = PyPlot.pywrap(PyPlot.pyimport("matplotlib.ticker"))
|
const pyticker = PyPlot.pyimport("matplotlib.ticker")
|
||||||
const pycmap = PyPlot.pywrap(PyPlot.pyimport("matplotlib.cm"))
|
const pycmap = PyPlot.pyimport("matplotlib.cm")
|
||||||
const pynp = PyPlot.pywrap(PyPlot.pyimport("numpy"))
|
const pynp = PyPlot.pyimport("numpy")
|
||||||
pynp.seterr(invalid="ignore")
|
pynp["seterr"](invalid="ignore")
|
||||||
const pytransforms = PyPlot.pywrap(PyPlot.pyimport("matplotlib.transforms"))
|
const pytransforms = PyPlot.pyimport("matplotlib.transforms")
|
||||||
const pycollections = PyPlot.pywrap(PyPlot.pyimport("matplotlib.collections"))
|
const pycollections = PyPlot.pyimport("matplotlib.collections")
|
||||||
const pyart3d = PyPlot.pywrap(PyPlot.pyimport("mpl_toolkits.mplot3d.art3d"))
|
const pyart3d = PyPlot.pyimport("mpl_toolkits.mplot3d.art3d")
|
||||||
|
|
||||||
# "support" matplotlib v1.5
|
# "support" matplotlib v1.5
|
||||||
const set_facecolor_sym = if PyPlot.version < v"2"
|
const set_facecolor_sym = if PyPlot.version < v"2"
|
||||||
@ -109,7 +109,7 @@ end
|
|||||||
|
|
||||||
# function py_colormap(c::ColorGradient, α=nothing)
|
# function py_colormap(c::ColorGradient, α=nothing)
|
||||||
# pyvals = [(v, py_color(getColorZ(c, v), α)) for v in c.values]
|
# pyvals = [(v, py_color(getColorZ(c, v), α)) for v in c.values]
|
||||||
# pycolors.pymember("LinearSegmentedColormap")[:from_list]("tmp", pyvals)
|
# pycolors["LinearSegmentedColormap"][:from_list]("tmp", pyvals)
|
||||||
# end
|
# end
|
||||||
|
|
||||||
# # convert vectors and ColorVectors to standard ColorGradients
|
# # convert vectors and ColorVectors to standard ColorGradients
|
||||||
@ -126,7 +126,7 @@ py_color(grad::ColorGradient) = py_color(grad.colors)
|
|||||||
|
|
||||||
function py_colormap(grad::ColorGradient)
|
function py_colormap(grad::ColorGradient)
|
||||||
pyvals = [(z, py_color(grad[z])) for z in grad.values]
|
pyvals = [(z, py_color(grad[z])) for z in grad.values]
|
||||||
cm = pycolors.LinearSegmentedColormap[:from_list]("tmp", pyvals)
|
cm = pycolors["LinearSegmentedColormap"][:from_list]("tmp", pyvals)
|
||||||
cm[:set_bad](color=(0,0,0,0.0), alpha=0.0)
|
cm[:set_bad](color=(0,0,0,0.0), alpha=0.0)
|
||||||
cm
|
cm
|
||||||
end
|
end
|
||||||
@ -135,7 +135,7 @@ py_colormap(c) = py_colormap(cgrad())
|
|||||||
|
|
||||||
function py_shading(c, z)
|
function py_shading(c, z)
|
||||||
cmap = py_colormap(c)
|
cmap = py_colormap(c)
|
||||||
ls = pycolors.pymember("LightSource")(270,45)
|
ls = pycolors["LightSource"](270,45)
|
||||||
ls[:shade](z, cmap, vert_exag=0.1, blend_mode="soft")
|
ls[:shade](z, cmap, vert_exag=0.1, blend_mode="soft")
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -159,7 +159,7 @@ function py_marker(marker::Shape)
|
|||||||
mat[i,2] = y[i]
|
mat[i,2] = y[i]
|
||||||
end
|
end
|
||||||
mat[n+1,:] = mat[1,:]
|
mat[n+1,:] = mat[1,:]
|
||||||
pypath.pymember("Path")(mat)
|
pypath["Path"](mat)
|
||||||
end
|
end
|
||||||
|
|
||||||
const _path_MOVETO = UInt8(1)
|
const _path_MOVETO = UInt8(1)
|
||||||
@ -185,7 +185,7 @@ const _path_CLOSEPOLY = UInt8(79)
|
|||||||
# lastnan = nan
|
# lastnan = nan
|
||||||
# end
|
# end
|
||||||
# codes[n+1] = _path_CLOSEPOLY
|
# codes[n+1] = _path_CLOSEPOLY
|
||||||
# pypath.pymember("Path")(mat, codes)
|
# pypath["Path"](mat, codes)
|
||||||
# end
|
# end
|
||||||
|
|
||||||
# get the marker shape
|
# get the marker shape
|
||||||
@ -235,14 +235,14 @@ end
|
|||||||
|
|
||||||
# # untested... return a FontProperties object from a Plots.Font
|
# # untested... return a FontProperties object from a Plots.Font
|
||||||
# function py_font(font::Font)
|
# function py_font(font::Font)
|
||||||
# pyfont.pymember("FontProperties")(
|
# pyfont["FontProperties"](
|
||||||
# family = font.family,
|
# family = font.family,
|
||||||
# size = font.size
|
# size = font.size
|
||||||
# )
|
# )
|
||||||
# end
|
# end
|
||||||
|
|
||||||
function get_locator_and_formatter(vals::AVec)
|
function get_locator_and_formatter(vals::AVec)
|
||||||
pyticker.pymember("FixedLocator")(1:length(vals)), pyticker.pymember("FixedFormatter")(vals)
|
pyticker["FixedLocator"](1:length(vals)), pyticker["FixedFormatter"](vals)
|
||||||
end
|
end
|
||||||
|
|
||||||
function add_pyfixedformatter(cbar, vals::AVec)
|
function add_pyfixedformatter(cbar, vals::AVec)
|
||||||
@ -264,9 +264,9 @@ function labelfunc(scale::Symbol, backend::PyPlotBackend)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function py_mask_nans(z)
|
function py_mask_nans(z)
|
||||||
# PyPlot.pywrap(pynp.ma[:masked_invalid](PyPlot.pywrap(z)))
|
# pynp["ma"][:masked_invalid](z)))
|
||||||
PyCall.pycall(pynp.ma[:masked_invalid], Any, z)
|
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
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
@ -497,7 +497,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
|
|||||||
extrakw = KW()
|
extrakw = KW()
|
||||||
isfinite(clims[1]) && (extrakw[:vmin] = clims[1])
|
isfinite(clims[1]) && (extrakw[:vmin] = clims[1])
|
||||||
isfinite(clims[2]) && (extrakw[:vmax] = clims[2])
|
isfinite(clims[2]) && (extrakw[:vmax] = clims[2])
|
||||||
kw[:norm] = pycolors.Normalize(; extrakw...)
|
kw[:norm] = pycolors["Normalize"](; extrakw...)
|
||||||
end
|
end
|
||||||
lz = collect(series[:line_z])
|
lz = collect(series[:line_z])
|
||||||
handle = if is3d(st)
|
handle = if is3d(st)
|
||||||
@ -508,7 +508,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
|
|||||||
# for i=1:n
|
# for i=1:n
|
||||||
# segments[i] = [(_cycle(x,i), _cycle(y,i), _cycle(z,i)), (_cycle(x,i+1), _cycle(y,i+1), _cycle(z,i+1))]
|
# segments[i] = [(_cycle(x,i), _cycle(y,i), _cycle(z,i)), (_cycle(x,i+1), _cycle(y,i+1), _cycle(z,i+1))]
|
||||||
# end
|
# end
|
||||||
lc = pyart3d.Line3DCollection(segments; kw...)
|
lc = pyart3d["Line3DCollection"](segments; kw...)
|
||||||
lc[:set_array](lz)
|
lc[:set_array](lz)
|
||||||
ax[:add_collection3d](lc, zs=z) #, zdir='y')
|
ax[:add_collection3d](lc, zs=z) #, zdir='y')
|
||||||
lc
|
lc
|
||||||
@ -520,7 +520,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
|
|||||||
# for i=1:n
|
# for i=1:n
|
||||||
# segments[i] = [(_cycle(x,i), _cycle(y,i)), (_cycle(x,i+1), _cycle(y,i+1))]
|
# segments[i] = [(_cycle(x,i), _cycle(y,i)), (_cycle(x,i+1), _cycle(y,i+1))]
|
||||||
# end
|
# end
|
||||||
lc = pycollections.LineCollection(segments; kw...)
|
lc = pycollections["LineCollection"](segments; kw...)
|
||||||
lc[:set_array](lz)
|
lc[:set_array](lz)
|
||||||
ax[:add_collection](lc)
|
ax[:add_collection](lc)
|
||||||
lc
|
lc
|
||||||
@ -805,8 +805,8 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
|
|||||||
handle = []
|
handle = []
|
||||||
for (i,rng) in enumerate(iter_segments(x, y))
|
for (i,rng) in enumerate(iter_segments(x, y))
|
||||||
if length(rng) > 1
|
if length(rng) > 1
|
||||||
path = pypath.pymember("Path")(hcat(x[rng], y[rng]))
|
path = pypath["Path"](hcat(x[rng], y[rng]))
|
||||||
patches = pypatches.pymember("PathPatch")(
|
patches = pypatches["PathPatch"](
|
||||||
path;
|
path;
|
||||||
label = series[:label],
|
label = series[:label],
|
||||||
zorder = series[:series_plotindex],
|
zorder = series[:series_plotindex],
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user