Elliptical plot markers with specifiable height and width?

I would like to create a plot using elliptical markers where the height and width of the elliptical marker can be specified, for each point in my case.

My intention is for the height to represent standard deviation at that point, the centre being the mean value and the width to represent the significance or importance of that point. However I don’t think such a marker exists (yet) or may be I am missing some statistical or other plot method to do this, so I wonder if people may suggest ways I could achieve such a marker or alternative ways to produce my plot?

At first I thought using a combination of the sin and cos functions, as in the plots documentation, would be one answer, but the marker width needs to be independent of the horizontal axis, so that plan looked unnecessarily complex and hence I thought I’d better ask for some ideas first.

1 Like

Perhaps you are looking for a covariance plot recipe: https://github.com/JuliaPlots/StatsPlots.jl#covariance-ellipses

2 Likes

I did, belatedly, get around to investigating @juliohm’s suggestion of covariance-ellipses which led me to another option using the Shape() function, which may be easier to use in the time series application I have in mind.

Here is some crude code to generate a series of ellipse shapes to illustrate the sort of thing I am trying to do, the ellipses position and dimensions will relate to real world data in the future:

using Plots

rng = range(0, 2π, length = 17)   # length = odd number for symmetric vertices.
ellipse(posx, posy, width, height) = Shape(width*sin.(rng).+posx, height*cos.(rng).+posy)
elps = [ellipse(x,rand(),rand(),rand()) for x ∈ 1:16]
plot(elps)

(you are welcome to educate me on improving my Julia coding)

I am not sure yet if this is a solution to my problem but it looks promising.

The following proposal uses a mix of vertical error bars (for standard deviation) and circles that increase in radius and become more transparent (yet not invisible) for less significant data. It will need further tweaking for your specific dataset.

PS: this is a random example for illustration purposes only, where standard deviation and significance are not correlated.

using Plots
N=40; x = LinRange(0,20,N); y = sin.(x)
σx = rand(N);  # significance should be normalized from 0 to 1
σy = 0.1rand(N); # y standard deviation
plot(x,y, lc=:white, yerror=σy, xlabel="time (s)",ylabel="Amplitude",label=false)
plot!(0:0.1:20, sin,lw=0.1, size=(800,600),label=false)
scatter!(x,y, ma=1.1.-σx, ms=1.0.+5*σx, mc=:red,lw=0,label=false)

1 Like