天道酬勤,学无止境

plots.jl

Adding global title to Plots.jl subplots

Question I would like to add a global title to a group of subplots using Plots.jl. Ideally, I'd do something like: using Plots pyplot() plot(rand(10,2), plot_title="Main title", title=["A" "B"], layout=2) but, as per the Plots.jl documentation, the plot_title attribute is not yet implemented: Title for the whole plot (not the subplots) (Note: Not currently implemented) In the meanwhile, is there any way around it? I'm currently using the pyplot backend, but I'm not especially tied to it. Answer1 This is a bit of a hack, but should be agnostic to the backend. Basically create a new plot where

2021-12-22 02:22:50    分类:技术分享    julia   plots.jl

Plotly + Julia + Latex

Question I would like to use latex with the Plotly backend. Look in this example: Even the x-axis and y-axis log scales are not formatted properly! Do you know how to do that? Best, v. using Plots, LaTeXStrings plotlyjs() x = 10 .^ LinRange(-5,5,10) plot(x, 1 ./ x, yaxis=:log, xaxis=:log, m = 2, xlabel="x", label="1/x",ylabel="f(x)") plot!(x, 10 ./ x, m=2,label="10/x") plot!(x, 1 ./ (x.^2), m=2, label=L"f(x)=$1/x^2$") savefig("./test.png") Answer1 Seems to work with the gr() backend, so I expect LaTeXString is not supported by the plotlyjs() backend.

2021-10-30 18:01:16    分类:技术分享    latex   julia   plotly   plots.jl

How to scale the fontsizes using Plots.jl

Question is there a way to rescale all the fontsizes (legend, tickslabels, axislabels…) at once? Original question from Filippo Vicentini on Slack. Answer1 Individual font sizes can be controlled with the titlefontsize, tickfontsize, legendfontsize, tickfontsize, guidefontsize and legendtitlefontsize attributes, but I get that this can be quite tedious. There is also the thickness_scaling attribute. plot(rand(10), thickness_scaling = 0.5) However, this also affects the line widths. The third option is to call Plots.scalefontsizes(α) to scale all font sizes by a factor α. This changes the

2021-10-25 09:59:10    分类:技术分享    plot   julia   plots.jl

Accessing backend specific functionality with Julia Plots

Question Plots is simple and powerful but sometimes I would like to have a little bit more control over individual elements of the plot to fine-tune its appearance. Is it possible to update the plot object of the backend directly? E.g., for the default pyplot backend, I tried using Plots p = plot(sin) p.o[:axes][1][:xaxis][:set_ticks_position]("top") but the plot does not change. Calling p.o[:show]() afterwards does not help, either. In other words: Is there a way to use the PyPlot interface for a plot that was initially created with Plots? Edit: The changes to the PyPlot object become visible

2021-10-09 22:35:55    分类:技术分享    matplotlib   julia   plots.jl

How plot on Images with Plots.jl?

Question I want using Plots.jl for plot on Images, for example simple sinusoid. Here my code: using Plots using Images gr() h = 400 w = 600 a = Array(RGB{FixedPointNumbers.UFixed{UInt8,8}}, h, w) img = Image(a) p=plot(img) x = collect(0:0.1:2π) plot!(x,sin(x)) png("Test") But I get wrong result. How do this correctly? Answer1 Here's a quick example that I hope gives you some clues: julia> plot(img) julia> plot!(x->200sin(.05x)+300, 0, 700, w=5) You probably just want to ensure that you're plotting to the right coordinates that match the image.

2021-10-09 06:13:12    分类:技术分享    julia   plots.jl

Julia PyPlot: plot 3D surface with as face colors the norm of surface gradient

Question Does anyone know how to plot a 3D surface with Julia's Pyplot with e.g the norm of the surface-gradient as the face color? Similar to this topic for Python: Color matplotlib plot_surface command with surface gradient Answer1 I saw this and I just HAD to make it work. It was almost supported out of the box with Plots.jl, using the PyPlot backend. I just had to swap out for a custom matplotlib shader to apply a different z-matrix. You'll notice that I'm accessing numpy's gradient function (imported through PyCall), and I'm wrapping the gradient matrix G so that it doesn't get sliced

2021-10-07 04:45:31    分类:技术分享    matplotlib   julia   plots.jl