Pyplot: how to change the marker color in a plot?



I am trying to plot two curves in the same plot by using pyplot.
I would appreciate if the 2 different curves had different colors. When it comes to the line, I managed to change it from the default blue color to e.g. green, by writing:

 line = (:path, "green")

The problem is that I also need markers, but I haven’t managed to change their colour too: no matter the line color, they remain blue (like the default color).
Any suggestions?
My code is like:

#    First curve
wanted_font = "garamond"
fig_1 = plot(x_axis_values, y_axis_values, c = [1], # I added c=[1] to not get a warning message, as suggested in another post/forum, I'm not sure about the meaning
title  = "My title",
titlefont = wanted_font, tickfont  = wanted_font, legendfont = wanted_font, guidefont = wanted_font,
xlabel    = "Year", ylabel    = "Magnitude",
legend    = true, legend    = :topleft,
label     = "Trend in scenario 1",
grid      = false,
marker    = (:circle, 4),

#   Second curve
plot!(fig_1, x_axis_values, second_y_axis_values,
c = [1], # I added c=[1] to not get a warning message, as suggested in another post/forum, I'm not sure about the meaning
label     = "Trend in scenario 2",
line      = (:path, "green"),  # Here I change the line color
marker    = (:diamond, 4), 
# Missing: something to change the marker color too ....

Thank you in advance!


Remember that pyplot is matplotlib, so you can simply search on matplotlib + marker color

looks like you can define marker face color, edge color, etc… so it depends on what you want to do.


plot(1:10,1:10,"o", markerfacecolor="g")
1 Like

@purplishrock thanks for your reply.
However, I tried:

using Plots

plot(1:10,1:10,"o", markerfacecolor="g")

And I get the following error:

ERROR: No user recipe defined for String
 [1] macro expansion at C:\Users\username\.julia\v0.6\Plots\src\series.jl:133 [inlined]
 [2] apply_recipe(::Dict{Symbol,Any}, ::Type{Plots.SliceIt}, ::UnitRange{Int64}, ::UnitRange{Int64}, ::String) at C:\Users\username\.julia\v0.6\RecipesBase\src\RecipesBase.jl:291
 [3] _process_userrecipes(::Plots.Plot{Plots.PyPlotBackend}, ::Dict{Symbol,Any}, ::Tuple{UnitRange{Int64},UnitRange{Int64},String}) at C:\Users\username\.julia\v0.6\Plots\src\pipeline.jl:81
 [4] _plot!(::Plots.Plot{Plots.PyPlotBackend}, ::Dict{Symbol,Any}, ::Tuple{UnitRange{Int64},UnitRange{Int64},String}) at C:\Users\username\.julia\v0.6\Plots\src\plot.jl:179
 [5] #plot#212(::Array{Any,1}, ::Function, ::UnitRange{Int64}, ::Vararg{Any,N} where N) at C:\Users\username\.julia\v0.6\Plots\src\plot.jl:58
 [6] (::RecipesBase.#kw##plot)(::Array{Any,1}, ::RecipesBase.#plot, ::UnitRange{Int64}, ::UnitRange{Int64}, ::Vararg{Any,N} where N) at .\<missing>:0
 [7] macro expansion at C:\Users\username\.julia\v0.6\Atom\src\repl.jl:118 [inlined]
 [8] anonymous at .\<missing>:?

Any explanation?


You are using Plots and I always specifically use Pyplot, i.e.

using PyPlot

I didn’t notice that you were using the Plots package in your example.
You need to consult the Plot package documentation, it will have a different interface.
I took a (very) quick look at the Plots documentation and it looks like

markercolor = :green

should do what you want.

1 Like