Skip to content

Commit 67305af

Browse files
committed
fix bar chart for strings with Julia 1.x
1 parent b44e66f commit 67305af

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/PyPlot.jl

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11

22
"""
3-
PyPlot allows Julia to interface with the Matplotlib library in Python, specifically the matplotlib.pyplot module, so you can create beautiful plots in Julia with your favorite Python package.
3+
PyPlot allows Julia to interface with the Matplotlib library in Python, specifically the matplotlib.pyplot module, so you can create beautiful plots in Julia with your favorite Python package.
44
5-
Only the currently documented matplotlib.pyplot API is exported. To use other functions in the module, you can also call matplotlib.pyplot.foo(...) as plt.foo(...).
5+
Only the currently documented matplotlib.pyplot API is exported. To use other functions in the module, you can also call matplotlib.pyplot.foo(...) as plt.foo(...).
66
For example, plt.plot(x, y) also works. (And the raw PyObject for the matplotlib modules is also accessible as PyPlot.matplotlib.)
77
8-
In general, all the arguments are the same as in Python.
8+
In general, all the arguments are the same as in Python.
99
1010
Here's a brief demo of a simple plot in Julia:
11-
11+
1212
using PyPlot
1313
x = range(0; stop=2*pi, length=1000); y = sin.(3 * x + 4 * cos.(2 * x));
1414
plot(x, y, color="red", linewidth=2.0, linestyle="--")
@@ -220,14 +220,15 @@ include("colormaps.jl")
220220
###########################################################################
221221
# Support array of string labels in bar chart
222222

223-
function bar(x::AbstractVector{T}, y; kws...) where T<:AbstractString
223+
function bar(x::AbstractVector{<:AbstractString}, y; kws_...)
224+
kws = Dict{Any,Any}(kws_)
224225
xi = 1:length(x)
225-
if !any(kw -> kw[1] == :align, kws)
226-
push!(kws, (:align, "center"))
226+
if !any(==(:align), keys(kws))
227+
kws[:align] = "center"
227228
end
228229
p = bar(xi, y; kws...)
229230
ax = any(kw -> kw[1] == :orientation && lowercase(kw[2]) == "horizontal",
230-
kws) ? gca()."yaxis" : gca()."xaxis"
231+
pairs(kws)) ? gca()."yaxis" : gca()."xaxis"
231232
ax."set_ticks"(xi)
232233
ax."set_ticklabels"(x)
233234
return p

0 commit comments

Comments
 (0)