Simple but seemingly non-answered question:
Is it possible to customize the legend in Plots.jl so as to have the different
text labels in different text colors? With the GR backend.
You can get this to work with legendfontcolor, if you use one plot! statement per color:
julia> using Plots
julia> plot(rand(10), linecolor = :red, legendfontcolor=:red)
julia> plot!(rand(10), linecolor = :blue, legendfontcolor=:blue)
Related
I have a scatter plot generated using Plots.jl in Julia via Plots.scatter(x, y, marker_z = z). This results in a scatter plot of x and y, where points are colored according to the corresponding values in z. There is a vertical color bar to the right of the scatter plot that indicates what colors correspond to what values of z.
I would like to modify the vertical color bar but was not able to find any details on how best to do this. The specific tasks I am interested in are:
I would like to add a label for the color bar.
I would like to modify the ticks on the color bar.
Use colorbar_ticks and colorbar_title
using Plots
pyplot()
colorbar_ticks=(0:0.2:1.0, string.(round.(Int, (0:0.2:1.0) .* 100), "%"))
Plots.scatter(rand(10), rand(10), marker_z = rand(10), colorbar_ticks=colorbar_ticks,clim=(0,1), colorbar_title="My title")
I have a plot with intersecting lines:
And I would like to add a tag or pointer which point to the intersection and display the coordinates of the intersection. Something like this:
I know the coordinates of the intersection and I know that the function annotate! adds text to the plot. However, I do not know how to add a line or arrow to point to the intersection and how to determine the right position for the text.
I agree that this isn't the most user-friendly thing to do, but I think it's also not that easy to implement (fwiw when I do this in practice I often resort to just exporting to PowerPoint and then annotating the plot there manually) - but here's a way to do it:
julia> using Plots
julia> plot(x -> x^2, 0:0.01:2); hline!([1], color = :red, linestyle = :dash); vline!([1], color = :green, linestyle = :dash)
julia> quiver!([0.5], [2], quiver = ([0.475], [-0.95]))
julia> annotate!([0.5], [2.1], text("This point is (1,1)"), valign = :top)
I am trying to apply a colormap when plotting an array of numbers in Julia 1.4.1, but all plot entries appear to only use the first color in the map. For instance:
using Plots
plot([1:10], rand(10,5), c=:viridis)
No colour change occurs even when I increase the number of plot entries to 1000:
plot([1:10], rand(10,1000), c=:viridis)
I have tried to apply the map using color or cgrad too, but had no success. So this leaves me wondering: how can I apply this colourmap such that it correctly spans the number of plot entries?
Do you want each line to use a different color?
I think you are looking for the palette argument.
First,create the color palette based on viridis, as suggested by Anshul in the comments (see end for alternative method).
julia> using Plots
julia> p = Plots.palette(:viridis, 11)
In the last code, 11 is the number of lines
Now, let's plot using the palette argument.
julia> plot( [1:10], rand(10,11), palette=p )
Alternative method to create the palette is creating a color gradient function
julia> C(g::ColorGradient) = RGB[ g[z] for z in range(0,stop=1,length=11) ]
We define the palette using that function
julia> g = :viridis
julia> p = C(cgrad(g))
I'm trying to make a bar plot using Plots.jl and the GR backend and wanted to ask how to make the x axis display text labels rather than numbers. Basically this is what I'm doing:
using Plots; gr()
data = [1,2,3]
labels = ["one","two","three"]
bar(data, legend=false)
This produces the following plot:
How do I display my labels ("one", "two", "three"), instead of "1 2 3" on the x axis?
Thanks!
The answer (thanks Tom!) is to pass the labels as x values (currently only possible on the dev branch):
Pkg.checkout("Plots","dev")
using Plots
gr()
data = [1,2,3]
labels = ["one","two","three"]
bar(labels, data, legend=false)
In the Plots version v1.38.0, one can do it by specifying the labels in the optional keyword argument xticks:
data = [1,2,3]
labels = ["one","two","three"]
bar(
data,
legend=false,
xticks=(1:length(data), labels)
)
I am plotting:
p " file1" u ($2-0.25):8:(.2) every ::1::568, "file2" u ($2):8:(.2) every ::568::1136, "file3" u ($2+0.25):8:(.2) every ::1137::1705
It produces three different keys and three different colour lines. However, I would also like to have the three of them using the same colour and the same legend (key). Is that possible?
You can specify title and linecolor (or fill) for each datafile. To remove the legend entry, use notitle.
plot sin(x), cos(x) linecolor 1 notitle