# Suggestion on this plot

**URL:** <https://discourse.julialang.org/t/suggestion-on-this-plot/107723>\
**Category:** General Usage\
**Tags:** plotting\
**Created:** [December 17, 2023, 3:01am UTC](https://discourse.julialang.org/t/suggestion-on-this-plot/107723 "2023-12-17T03:01:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Josa9321](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/josa9321/32/12170_2.png) [@Josa9321](https://discourse.julialang.org/u/Josa9321)\
**Post date:** [December 17, 2023, 3:01am UTC](https://discourse.julialang.org/t/suggestion-on-this-plot/107723/1 "2023-12-17T03:01:16Z")

</div>

Is there any easier way of doing this kind of plot?

 ![image](https://global.discourse-cdn.com/julialang/original/3X/7/1/71c78725a714faaa2f4abfb23284a09de0561f51.png)

Instead of just x\_1, I would put a value, x\_1 = 100 for example.

The way I think it would need to adapt a little the quiver plot and another plots, as here [Plotting vector fields](https://discourse.julialang.org/t/plotting-vector-fields/32704). But I don’t think it would be a good way of doing it.

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [December 17, 2023, 8:44pm UTC](https://discourse.julialang.org/t/suggestion-on-this-plot/107723/2 "2023-12-17T20:44:42Z")

</div>

> [@Josa9321](#):
>
> Is there any easier way of doing this kind of plot?

Easier than what?

---

<div class="post-metadata">

**Author:** ![StevenSiew](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevensiew/32/218393_2.png) [@StevenSiew](https://discourse.julialang.org/u/StevenSiew)\
**Post date:** [December 17, 2023, 8:50pm UTC](https://discourse.julialang.org/t/suggestion-on-this-plot/107723/3 "2023-12-17T20:50:58Z")

</div>

This is not a plot. This is a diagram. Have you tried Luxor?

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [December 18, 2023, 9:21pm UTC](https://discourse.julialang.org/t/suggestion-on-this-plot/107723/4 "2023-12-18T21:21:26Z")

</div>

OP’s annotated plot, could be conveniently generated using Plots.jl 's `quiver!()` and `annotate!()` together with LaTeXStrings.jl.

---

<div class="post-metadata">

**Author:** ![runjaj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/runjaj/32/23628_2.png) [@runjaj](https://discourse.julialang.org/u/runjaj)\
**Post date:** [December 19, 2023, 11:27am UTC](https://discourse.julialang.org/t/suggestion-on-this-plot/107723/5 "2023-12-19T11:27:06Z")

</div>

I think it can be done quite easily using [Kroki.jl](https://github.com/bauglir/Kroki.jl).

I created a function that creates your diagram using Kroki. The input is a vector with the labels for x₁, x₂, etc. I believe the code is easy to understand. I used [Pikchr](https://pikchr.org) to create the diagram:

```julia
using Kroki

function chart(x)
	# Function to get the subindex of a figure
	sub(i) = Char(0x2080+i)

	# First arrow
	chart = """
	arrow "s$(sub(0)) = 0" above
	"""
	
	unit(i, idx) = """
		circle fill black
		arrow <- up from last circle.n
		"$(x[idx])"
		arrow "xr$i " rjust down <- from last circle.s
		arrow down 85% right 85% from last circle.se
		"d$i"
		arrow "s$i$(idx==length(x) ? "=0" : "")" above right from last circle.e
	"""
	
	for idx in 1:length(x)
		i = sub(idx)
		chart *= unit(i, idx)
	end
	
	Diagram(:pikchr, chart)
end

```

With `chart([100, 2, 3, 400, 5])` you get:

 ![chart5](https://global.discourse-cdn.com/julialang/original/3X/c/0/c0453b1ffb6b3b4669c7f22a2499dbabbe28e270.png)

It’ easy to change the lengths of the arrows, the diameter of the circles or write the labels in italics.

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [December 19, 2023, 11:35pm UTC](https://discourse.julialang.org/t/suggestion-on-this-plot/107723/6 "2023-12-19T23:35:31Z")

</div>

Fyi, with Plots.jl, it takes 30 lines of code to produce:

 ![Plots_repetitive_diagram](https://global.discourse-cdn.com/julialang/original/3X/5/8/58b9f95f6fc81af4743c612ac07dfa84a855decf.png)

> **Plots .jl code**
>
> ```julia
> using LaTeXStrings, Plots; gr(dpi=600)
> 
> const l, r, cθ, δ, fs = 1, 0.25, cosd(45), 0.12, 18
> const vs, vxr, vx, vd = (l, 0), (0, l), (0, -l),(l*cθ, -l*cθ)
> 
> circle(x) = Shape(map(z -> z .+ (x + l + r, 0), Plots.partialcircle(0, 2π, 100, r)))
> 
> function unit_diagram!(x, xi_str, si_str, xri_str, di_str)
> plot!(circle(x), c=:black, fill=:black)
> quiver!((x+l+2r, 0), quiver=([vs[1]],vs[2]), c=:black, arrow=:closed)
> quiver!((x+l+r, l+r), quiver=([vx[1]],vx[2]), c=:black, arrow=:closed)
> quiver!((x+l+r, -(l+r)), quiver=([vx[1]],-vx[2]), c=:black, arrow=:closed)
> quiver!((x+l+r+r*cθ, -r*cθ), quiver=([vd[1]],vd[2]), c=:black, arrow=:closed)
> annotate!(x+l+r-δ/2, -0.8*l, text(xri_str, :right, fs))
> annotate!(x+l+r, l+r+δ, text(xi_str, :center, fs))
> annotate!(x+2l, δ, text(si_str, :center, fs))
> annotate!(x+(l+r)*(1+cθ)+δ, -(l+r)*cθ - δ, text(di_str, :center, fs))
> end
> 
> function plot_diagram(n, vstr)
> p = plot((0,0), ratio=:equal, framestyle=:none, size=(1200,600)) # size=(1200,600)
> quiver!((0,0), quiver=([vs[1]],vs[2]), c=:black, arrow=:closed)
> annotate!(l/2, δ, text(L"s_0 = 0", :center, fs))
> for i in 1:n
> si = i == n ? L"s_%$i = 0" : L"s_%$i"
> stri = vstr[i]
> !isempty(stri) && (stri = " = $stri")
> unit_diagram!((i-1)*(l+2r), L"x_%$i%$stri", si, L"xr_%$i", L"d_%$i")
> end
> return p
> end
> 
> plot_diagram(5, ["100", "", "", "", ""])
> 
> ```
