Fixed colormap problem
This commit is contained in:
parent
925243969c
commit
7546db4d42
@ -5,6 +5,9 @@
|
|||||||
supportedArgs(::GRBackend) = [
|
supportedArgs(::GRBackend) = [
|
||||||
:annotation,
|
:annotation,
|
||||||
:background_color, :foreground_color, :color_palette,
|
:background_color, :foreground_color, :color_palette,
|
||||||
|
:background_color_legend, :background_color_inside, :background_color_outside,
|
||||||
|
:foreground_color_legend, :foreground_color_grid, :foreground_color_axis,
|
||||||
|
:foreground_color_text, :foreground_color_border,
|
||||||
:group,
|
:group,
|
||||||
:label,
|
:label,
|
||||||
:linetype,
|
:linetype,
|
||||||
@ -30,6 +33,7 @@ supportedArgs(::GRBackend) = [
|
|||||||
:orientation,
|
:orientation,
|
||||||
:overwrite_figure,
|
:overwrite_figure,
|
||||||
:polar,
|
:polar,
|
||||||
|
:aspect_ratio
|
||||||
]
|
]
|
||||||
supportedAxes(::GRBackend) = _allAxes
|
supportedAxes(::GRBackend) = _allAxes
|
||||||
supportedTypes(::GRBackend) = [:none, :line, :path, :steppre, :steppost, :sticks,
|
supportedTypes(::GRBackend) = [:none, :line, :path, :steppre, :steppost, :sticks,
|
||||||
@ -85,7 +89,7 @@ function gr_getaxisind(p)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function gr_setmarkershape(p)
|
function gr_setmarkershape(p)
|
||||||
if haskey(p, :markershape)
|
if p[:markershape] != :none
|
||||||
shape = p[:markershape]
|
shape = p[:markershape]
|
||||||
if isa(shape, Shape)
|
if isa(shape, Shape)
|
||||||
p[:vertices] = vertices(shape)
|
p[:vertices] = vertices(shape)
|
||||||
@ -167,7 +171,6 @@ function gr_polaraxes(rmin, rmax)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function gr_getzlims(d, zmin, zmax, adjust)
|
function gr_getzlims(d, zmin, zmax, adjust)
|
||||||
if haskey(d, :zlims)
|
|
||||||
if d[:zlims] != :auto
|
if d[:zlims] != :auto
|
||||||
zlims = d[:zlims]
|
zlims = d[:zlims]
|
||||||
if zlims[1] != NaN
|
if zlims[1] != NaN
|
||||||
@ -178,7 +181,6 @@ function gr_getzlims(d, zmin, zmax, adjust)
|
|||||||
end
|
end
|
||||||
adjust = false
|
adjust = false
|
||||||
end
|
end
|
||||||
end
|
|
||||||
if adjust
|
if adjust
|
||||||
zmin, zmax = GR.adjustrange(zmin, zmax)
|
zmin, zmax = GR.adjustrange(zmin, zmax)
|
||||||
end
|
end
|
||||||
@ -218,23 +220,18 @@ function gr_display(plt::Plot{GRBackend}, clear=true, update=true,
|
|||||||
end
|
end
|
||||||
viewport[4] = vp[3] + 0.95 * (vp[4] - vp[3])
|
viewport[4] = vp[3] + 0.95 * (vp[4] - vp[3])
|
||||||
|
|
||||||
if haskey(d, :background_color)
|
bg = gr_getcolorind(d[:background_color]) # TODO: background for all subplots?
|
||||||
|
fg = gr_getcolorind(d[:foreground_color])
|
||||||
|
|
||||||
GR.savestate()
|
GR.savestate()
|
||||||
GR.selntran(0)
|
GR.selntran(0)
|
||||||
GR.setfillintstyle(GR.INTSTYLE_SOLID)
|
GR.setfillintstyle(GR.INTSTYLE_SOLID)
|
||||||
GR.setfillcolorind(gr_getcolorind(d[:background_color]))
|
GR.setfillcolorind(gr_getcolorind(d[:background_color_outside]))
|
||||||
GR.fillrect(vp[1], vp[2], vp[3], vp[4])
|
GR.fillrect(vp[1], vp[2], vp[3], vp[4])
|
||||||
|
GR.setfillcolorind(gr_getcolorind(d[:background_color_inside]))
|
||||||
|
GR.fillrect(viewport[1], viewport[2], viewport[3], viewport[4])
|
||||||
GR.selntran(1)
|
GR.selntran(1)
|
||||||
GR.restorestate()
|
GR.restorestate()
|
||||||
c = getColor(d[:background_color])
|
|
||||||
if 0.21 * c.r + 0.72 * c.g + 0.07 * c.b < 0.9
|
|
||||||
fg = convert(Int, GR.inqcolorfromrgb(1-c.r, 1-c.g, 1-c.b))
|
|
||||||
else
|
|
||||||
fg = 1
|
|
||||||
end
|
|
||||||
else
|
|
||||||
fg = 1
|
|
||||||
end
|
|
||||||
|
|
||||||
extrema = zeros(2, 4)
|
extrema = zeros(2, 4)
|
||||||
num_axes = 1
|
num_axes = 1
|
||||||
@ -260,11 +257,7 @@ function gr_display(plt::Plot{GRBackend}, clear=true, update=true,
|
|||||||
elseif lt == :ohlc
|
elseif lt == :ohlc
|
||||||
x, y = 1:size(p[:y], 1), p[:y]
|
x, y = 1:size(p[:y], 1), p[:y]
|
||||||
elseif lt in [:hist, :density]
|
elseif lt in [:hist, :density]
|
||||||
if haskey(p, :bins)
|
|
||||||
x, y = Base.hist(p[:y], p[:bins])
|
x, y = Base.hist(p[:y], p[:bins])
|
||||||
else
|
|
||||||
x, y = Base.hist(p[:y])
|
|
||||||
end
|
|
||||||
elseif lt in [:hist2d, :hexbin]
|
elseif lt in [:hist2d, :hexbin]
|
||||||
E = zeros(length(p[:x]),2)
|
E = zeros(length(p[:x]),2)
|
||||||
E[:,1] = p[:x]
|
E[:,1] = p[:x]
|
||||||
@ -373,7 +366,7 @@ function gr_display(plt::Plot{GRBackend}, clear=true, update=true,
|
|||||||
|
|
||||||
if axes_2d
|
if axes_2d
|
||||||
GR.setlinewidth(1)
|
GR.setlinewidth(1)
|
||||||
GR.setlinecolorind(fg)
|
GR.setlinecolorind(gr_getcolorind(d[:foreground_color_grid]))
|
||||||
ticksize = 0.0075 * diag
|
ticksize = 0.0075 * diag
|
||||||
if outside_ticks
|
if outside_ticks
|
||||||
ticksize = -ticksize
|
ticksize = -ticksize
|
||||||
@ -381,6 +374,7 @@ function gr_display(plt::Plot{GRBackend}, clear=true, update=true,
|
|||||||
if grid_flag && fg == 1
|
if grid_flag && fg == 1
|
||||||
GR.grid(xtick, ytick, 0, 0, majorx, majory)
|
GR.grid(xtick, ytick, 0, 0, majorx, majory)
|
||||||
end
|
end
|
||||||
|
GR.setlinecolorind(gr_getcolorind(d[:foreground_color_axis]))
|
||||||
if num_axes == 1
|
if num_axes == 1
|
||||||
GR.axes(xtick, ytick, xorg[1], yorg[1], majorx, majory, ticksize)
|
GR.axes(xtick, ytick, xorg[1], yorg[1], majorx, majory, ticksize)
|
||||||
GR.axes(xtick, ytick, xorg[2], yorg[2], -majorx, -majory, -ticksize)
|
GR.axes(xtick, ytick, xorg[2], yorg[2], -majorx, -majory, -ticksize)
|
||||||
@ -423,27 +417,21 @@ function gr_display(plt::Plot{GRBackend}, clear=true, update=true,
|
|||||||
GR.restorestate()
|
GR.restorestate()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
GR.setcolormap(1000 + GR.COLORMAP_COOLWARM)
|
||||||
|
|
||||||
legend = false
|
legend = false
|
||||||
|
|
||||||
for p in plt.seriesargs
|
for p in plt.seriesargs
|
||||||
lt = p[:linetype]
|
lt = p[:linetype]
|
||||||
if lt in (:hist2d, :hexbin, :contour, :surface, :wireframe, :heatmap)
|
if lt in (:hist2d, :hexbin, :contour, :surface, :wireframe, :heatmap)
|
||||||
if isa(p[:fillcolor], ColorGradient)
|
if isa(p[:fillcolor], ColorGradient)
|
||||||
# TODO: this still isn't right... need to do something like in PyPlot for skewed gradients
|
grad = p[:fillcolor]
|
||||||
# cv = p[:fillcolor].colors
|
|
||||||
for (i,cz) in enumerate(linspace(0,1,256))
|
|
||||||
# c = cv[mod1(i,length(cv))]
|
|
||||||
c = getColorZ(p[:fillcolor], cz)
|
|
||||||
GR.setcolorrep(999+i, red(c), green(c), blue(c))
|
|
||||||
end
|
|
||||||
# if haskey(d, :color_palette)
|
|
||||||
# ci = 1000
|
|
||||||
# for cv in d[:color_palette]
|
|
||||||
# GR.setcolorrep(ci, cv.r, cv.g, cv.b)
|
|
||||||
# ci += 1
|
|
||||||
# end
|
|
||||||
else
|
else
|
||||||
GR.setcolormap(GR.COLORMAP_COOLWARM)
|
grad = default_gradient()
|
||||||
|
end
|
||||||
|
cs = [getColorZ(grad, z) for z in linspace(0, 1, 256)]
|
||||||
|
for (i, c) in enumerate(cs)
|
||||||
|
GR.setcolorrep(999+i, red(c), green(c), blue(c))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if get(d, :polar, false)
|
if get(d, :polar, false)
|
||||||
@ -453,17 +441,15 @@ function gr_display(plt::Plot{GRBackend}, clear=true, update=true,
|
|||||||
xmin, xmax, ymin, ymax = extrema[gr_getaxisind(p),:]
|
xmin, xmax, ymin, ymax = extrema[gr_getaxisind(p),:]
|
||||||
GR.setwindow(xmin, xmax, ymin, ymax)
|
GR.setwindow(xmin, xmax, ymin, ymax)
|
||||||
if lt in [:path, :line, :steppre, :steppost, :sticks, :hline, :vline, :ohlc, :polar]
|
if lt in [:path, :line, :steppre, :steppost, :sticks, :hline, :vline, :ohlc, :polar]
|
||||||
haskey(p, :linestyle) && GR.setlinetype(gr_linetype[p[:linestyle]])
|
GR.setlinetype(gr_linetype[p[:linestyle]])
|
||||||
haskey(p, :linewidth) && GR.setlinewidth(p[:linewidth])
|
GR.setlinewidth(p[:linewidth])
|
||||||
haskey(p, :linecolor) && GR.setlinecolorind(gr_getcolorind(p[:linecolor]))
|
GR.setlinecolorind(gr_getcolorind(p[:linecolor]))
|
||||||
end
|
end
|
||||||
if lt == :path
|
if lt == :path
|
||||||
if haskey(p, :fillcolor)
|
|
||||||
GR.setfillcolorind(gr_getcolorind(p[:fillcolor]))
|
|
||||||
GR.setfillintstyle(GR.INTSTYLE_SOLID)
|
|
||||||
end
|
|
||||||
if length(p[:x]) > 1
|
if length(p[:x]) > 1
|
||||||
if p[:fillrange] != nothing
|
if p[:fillrange] != nothing
|
||||||
|
GR.setfillcolorind(gr_getcolorind(p[:fillcolor]))
|
||||||
|
GR.setfillintstyle(GR.INTSTYLE_SOLID)
|
||||||
GR.fillarea([p[:x][1]; p[:x]; p[:x][length(p[:x])]], [p[:fillrange]; p[:y]; p[:fillrange]])
|
GR.fillarea([p[:x][1]; p[:x]; p[:x][length(p[:x])]], [p[:fillrange]; p[:y]; p[:fillrange]])
|
||||||
end
|
end
|
||||||
GR.polyline(p[:x], p[:y])
|
GR.polyline(p[:x], p[:y])
|
||||||
@ -502,9 +488,8 @@ function gr_display(plt::Plot{GRBackend}, clear=true, update=true,
|
|||||||
end
|
end
|
||||||
legend = true
|
legend = true
|
||||||
elseif lt == :scatter || (p[:markershape] != :none && axes_2d)
|
elseif lt == :scatter || (p[:markershape] != :none && axes_2d)
|
||||||
haskey(p, :markercolor) && GR.setmarkercolorind(gr_getcolorind(p[:markercolor]))
|
GR.setmarkercolorind(gr_getcolorind(p[:markercolor]))
|
||||||
gr_setmarkershape(p)
|
gr_setmarkershape(p)
|
||||||
if haskey(d, :markersize)
|
|
||||||
if typeof(p[:markersize]) <: Number
|
if typeof(p[:markersize]) <: Number
|
||||||
GR.setmarkersize(p[:markersize] / 4.0)
|
GR.setmarkersize(p[:markersize] / 4.0)
|
||||||
if length(p[:x]) > 0
|
if length(p[:x]) > 0
|
||||||
@ -522,11 +507,6 @@ function gr_display(plt::Plot{GRBackend}, clear=true, update=true,
|
|||||||
gr_polymarker(p, [p[:x][i]], [p[:y][i]])
|
gr_polymarker(p, [p[:x][i]], [p[:y][i]])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
|
||||||
if length(p[:x]) > 0
|
|
||||||
gr_polymarker(p, p[:x], p[:y])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
legend = true
|
legend = true
|
||||||
elseif lt == :bar
|
elseif lt == :bar
|
||||||
y = p[:y]
|
y = p[:y]
|
||||||
@ -534,22 +514,18 @@ function gr_display(plt::Plot{GRBackend}, clear=true, update=true,
|
|||||||
GR.setfillcolorind(gr_getcolorind(p[:fillcolor]))
|
GR.setfillcolorind(gr_getcolorind(p[:fillcolor]))
|
||||||
GR.setfillintstyle(GR.INTSTYLE_SOLID)
|
GR.setfillintstyle(GR.INTSTYLE_SOLID)
|
||||||
GR.fillrect(i-0.4, i+0.4, max(0, ymin), y[i])
|
GR.fillrect(i-0.4, i+0.4, max(0, ymin), y[i])
|
||||||
GR.setfillcolorind(1)
|
GR.setfillcolorind(fg)
|
||||||
GR.setfillintstyle(GR.INTSTYLE_HOLLOW)
|
GR.setfillintstyle(GR.INTSTYLE_HOLLOW)
|
||||||
GR.fillrect(i-0.4, i+0.4, max(0, ymin), y[i])
|
GR.fillrect(i-0.4, i+0.4, max(0, ymin), y[i])
|
||||||
end
|
end
|
||||||
elseif lt in [:hist, :density]
|
elseif lt in [:hist, :density]
|
||||||
if haskey(p, :bins)
|
|
||||||
h = Base.hist(p[:y], p[:bins])
|
h = Base.hist(p[:y], p[:bins])
|
||||||
else
|
|
||||||
h = Base.hist(p[:y])
|
|
||||||
end
|
|
||||||
x, y = float(collect(h[1])), float(h[2])
|
x, y = float(collect(h[1])), float(h[2])
|
||||||
for i = 2:length(y)
|
for i = 2:length(y)
|
||||||
GR.setfillcolorind(gr_getcolorind(p[:fillcolor]))
|
GR.setfillcolorind(gr_getcolorind(p[:fillcolor]))
|
||||||
GR.setfillintstyle(GR.INTSTYLE_SOLID)
|
GR.setfillintstyle(GR.INTSTYLE_SOLID)
|
||||||
GR.fillrect(x[i-1], x[i], ymin, y[i])
|
GR.fillrect(x[i-1], x[i], ymin, y[i])
|
||||||
GR.setfillcolorind(1)
|
GR.setfillcolorind(fg)
|
||||||
GR.setfillintstyle(GR.INTSTYLE_HOLLOW)
|
GR.setfillintstyle(GR.INTSTYLE_HOLLOW)
|
||||||
GR.fillrect(x[i-1], x[i], ymin, y[i])
|
GR.fillrect(x[i-1], x[i], ymin, y[i])
|
||||||
end
|
end
|
||||||
@ -660,15 +636,15 @@ function gr_display(plt::Plot{GRBackend}, clear=true, update=true,
|
|||||||
GR.grid3d(0, ytick, 0, xmax, ymin, zmin, 0, 2, 0)
|
GR.grid3d(0, ytick, 0, xmax, ymin, zmin, 0, 2, 0)
|
||||||
end
|
end
|
||||||
if lt == :scatter3d
|
if lt == :scatter3d
|
||||||
haskey(p, :markercolor) && GR.setmarkercolorind(gr_getcolorind(p[:markercolor]))
|
GR.setmarkercolorind(gr_getcolorind(p[:markercolor]))
|
||||||
gr_setmarkershape(p)
|
gr_setmarkershape(p)
|
||||||
for i = 1:length(z)
|
for i = 1:length(z)
|
||||||
px, py = GR.wc3towc(x[i], y[i], z[i])
|
px, py = GR.wc3towc(x[i], y[i], z[i])
|
||||||
gr_polymarker(p, [px], [py])
|
gr_polymarker(p, [px], [py])
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
haskey(p, :linewidth) && GR.setlinewidth(p[:linewidth])
|
|
||||||
if length(x) > 0
|
if length(x) > 0
|
||||||
|
GR.setlinewidth(p[:linewidth])
|
||||||
GR.polyline3d(x, y, z)
|
GR.polyline3d(x, y, z)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -774,21 +750,21 @@ function gr_display(plt::Plot{GRBackend}, clear=true, update=true,
|
|||||||
py = viewport[4] - 0.06
|
py = viewport[4] - 0.06
|
||||||
dy = 0.03 * sqrt((viewport[2] - viewport[1])^2 + (viewport[4] - viewport[3])^2)
|
dy = 0.03 * sqrt((viewport[2] - viewport[1])^2 + (viewport[4] - viewport[3])^2)
|
||||||
GR.setfillintstyle(GR.INTSTYLE_SOLID)
|
GR.setfillintstyle(GR.INTSTYLE_SOLID)
|
||||||
GR.setfillcolorind(0)
|
GR.setfillcolorind(gr_getcolorind(d[:background_color_legend]))
|
||||||
GR.fillrect(px - 0.08, px + w + 0.02, py + dy, py - dy * length(plt.seriesargs))
|
GR.fillrect(px - 0.08, px + w + 0.02, py + dy, py - dy * length(plt.seriesargs))
|
||||||
GR.setlinetype(1)
|
GR.setlinetype(1)
|
||||||
GR.setlinewidth(1)
|
GR.setlinewidth(1)
|
||||||
GR.drawrect(px - 0.08, px + w + 0.02, py + dy, py - dy * length(plt.seriesargs))
|
GR.drawrect(px - 0.08, px + w + 0.02, py + dy, py - dy * length(plt.seriesargs))
|
||||||
i = 0
|
i = 0
|
||||||
for p in plt.seriesargs
|
for p in plt.seriesargs
|
||||||
haskey(p, :linewidth) && GR.setlinewidth(p[:linewidth])
|
GR.setlinewidth(p[:linewidth])
|
||||||
if p[:linetype] in [:path, :line, :steppre, :steppost, :sticks]
|
if p[:linetype] in [:path, :line, :steppre, :steppost, :sticks]
|
||||||
haskey(p, :linecolor) && GR.setlinecolorind(gr_getcolorind(p[:linecolor]))
|
GR.setlinecolorind(gr_getcolorind(p[:linecolor]))
|
||||||
haskey(p, :linestyle) && GR.setlinetype(gr_linetype[p[:linestyle]])
|
GR.setlinetype(gr_linetype[p[:linestyle]])
|
||||||
GR.polyline([px - 0.07, px - 0.01], [py, py])
|
GR.polyline([px - 0.07, px - 0.01], [py, py])
|
||||||
end
|
end
|
||||||
if p[:linetype] == :scatter || p[:markershape] != :none
|
if p[:linetype] == :scatter || p[:markershape] != :none
|
||||||
haskey(p, :markercolor) && GR.setmarkercolorind(gr_getcolorind(p[:markercolor]))
|
GR.setmarkercolorind(gr_getcolorind(p[:markercolor]))
|
||||||
gr_setmarkershape(p)
|
gr_setmarkershape(p)
|
||||||
if p[:linetype] in [:path, :line, :steppre, :steppost, :sticks]
|
if p[:linetype] in [:path, :line, :steppre, :steppost, :sticks]
|
||||||
gr_polymarker(p, [px - 0.06, px - 0.02], [py, py])
|
gr_polymarker(p, [px - 0.06, px - 0.02], [py, py])
|
||||||
@ -803,7 +779,7 @@ function gr_display(plt::Plot{GRBackend}, clear=true, update=true,
|
|||||||
lab = p[:label]
|
lab = p[:label]
|
||||||
end
|
end
|
||||||
GR.settextalign(GR.TEXT_HALIGN_LEFT, GR.TEXT_VALIGN_HALF)
|
GR.settextalign(GR.TEXT_HALIGN_LEFT, GR.TEXT_VALIGN_HALF)
|
||||||
GR.settextcolorind(1)
|
GR.settextcolorind(gr_getcolorind(d[:foreground_color_legend]))
|
||||||
GR.text(px, py, lab)
|
GR.text(px, py, lab)
|
||||||
py -= dy
|
py -= dy
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user