Quiver plots with PlotlyJS

Hi. I am using a code written by @empet here to produce a quiver plot using PlotlyJS. It works very well if the ranges of the two variables are the same (in a system of differential equations). For example, the code below produces an immaculate plot (see the following image).

    α = 0.4
	n = 0.01
	δ = 0.1
	ρ = 0.02
	σ = 0.5
	g = 0.019 
	
	z_l = LinRange(0.0, 2.5, 26) 		# 26-element LinRange{Float64, Int64}
	w_l = LinRange(0.0, 2.5, 26) 		# 26-element LinRange{Float64, Int64}
	
	z = [zi for wi in w_l, zi in z_l] 	# z mesh grid
	w = [wi for wi in w_l, zi in z_l] 	# w mesh grid
	
	
	v = (1.0 ./ σ) .* (α .* w .^(α .- 1.0) .- (n .+ δ .+ ρ .+ (g .* σ))) .* z 	# the first differential equation
	u = w .^ α .- z .- (n .+ δ .+ g) .* w  										# the second differential equation
	
	q4=Quiver(x=w, y=z, u=u, v=v, vector_scale=0.06)
	
	fig4  = quiverPlot(q4; color="#8f180b")
	
	update!(fig4, line_width=0.75,  [1],  
		layout=Layout(width=650, height=650, plot_bgcolor="#faeee0", #vintage background color 
		template=nothing, xaxis_zeroline=false, yaxis_zeroline=false, xaxis_title=L"k(t)", 
		yaxis_title = L"c(t)",
		)
	)
	#relayout!(fig4, yaxis_range=[0 ,2.5])
	
	fig4

However, I need to have different ranges for the two variables. In this case, if I change one of the ranges to, e.g., the w_l range:

z_l = LinRange(0.0,  2.5, 26) 		# 26-element LinRange{Float64, Int64}
w_l = LinRange(0.0, 12.5, 26) 		# 26-element LinRange{Float64, Int64}

I get the following plot:

I tried to change the w and z mesh grids and @empet’s original code but had no luck. I also tried to change the xaxis_range, but it does not work. Apparently, the axes are truncated to the largest domain length.

How can I get rid of the two useless areas in the plot above? I would greatly appreciate any help.

Thanks.

Define both zl and wl with approximately the same distance between two consecutive points:

z_l = LinRange(0.0,  2.5, 12) 
w_l = LinRange(0.0, 12.5, 60)

and set in update!, xaxis_constrain="domain", yaxis_constrain="domain":

q4=Quiver(x=w, y=z, u=u, v=v, vector_scale=0.1)
fig4  = quiverPlot(q4; color="#8f180b")

update!(fig4, line_width=0.75,  [1],  
       layout=Layout( width=750, height=450, plot_bgcolor="#faeee0",  
       template=nothing, xaxis_zeroline=false, yaxis_zeroline=false, xaxis_title=L"k(t)", 
       yaxis_title = L"c(t)",  xaxis_constrain="domain", 
                            yaxis_constrain="domain"))
1 Like

Hi @empet. Thank you very much for your help. Your changes indeed plot the domains as intended. However, there is still something unwanted in the plot: the plotted area seems to be limited by the ratio of the two different ranges. For example, in the image below (produced by your new code), there are two large idle areas that are useless. Please see the image below.

Is the removal of those two areas a costly coding exercise? If so, please leave the problem as it stands now. If not, help will be much appreciated because, in most cases, the domains of the differential equations are different in a quiver plot, and all the examples I have seen in Julia use the same domain. Thanks a lot.

You get that extraspace when saving the figure?
with:

savefig(fig4, "quiver-pljs.png", width=750, height=450, scale=1)

I got this image:

When I save the plot, I get a PNG file exactly like yours above.

When the plot is displayed in Pluto or VSCcode, the figure is the same as yours, with the difference that the LaTeX in the axis titles is correctly rendered because I am using a package developed by @disberd (PlutoPlotly) that does that job correctly.

Thanks.

@VivMendes I haven’t realised if now it’s OK or not, because your hypothesis that the extra-space was related to x- range and y- range was false. No matter what trace and layout has your plot, the extra-space around the plot window can be reduced by setting margin, let us say, margin=attr(t=10, r=5, b=5, l=5), where these numbers represent pixels. In this case you should set a lower width and height.
What you get in your posted images is the space corresponding to default margin, with top, t=120 or so.

1 Like

I’m sorry. I forgot that I could play with the margin=attr() to manage the large margins generated by the plot. I will do so. This trick did not come to my mind because the extra margins do not appear in the case of the same range (first image above).

It is OK as it stands now. I marked the previous exchange as the solution. Thank you very much for your kind help.

1 Like