Repository navigation
Rotation of a Shape relative to its Layout #363
Description
Activity
@dustypomerleau The main problem is that
Plotly.jsdoesn't actually support a true ellipse shape, see plotly/plotly.js#4296 . The ones in the book are based on the Circle shape, but skewed, it is basically an axis aligned ellipse.Since plotly.rs is a wrapper on plotly.js, we inherit the same issue.
Sadly, the only option you have is to actually generate your own scatter trace with the ellipse equation and add it to your plot. This is what the python and js community has been doing so far. https://community.plotly.com/t/how-to-draw-ellipse-on-top-of-scatter-plot/36576/2
Thanks for the pointer, @andrei-ng. I think achieving this on a polar plot might require me to convert the dataset from polar to cartesian coordinates to do the calculations for the ellipse. It could be quite challenging (for me, at least). For the moment, I'll leave this open and post my solution if I find one.
Thanks for the pointer, @andrei-ng. I think achieving this on a polar plot might require me to convert the dataset from polar to cartesian coordinates to do the calculations for the ellipse. It could be quite challenging (for me, at least). For the moment, I'll leave this open and post my solution if I find one.
Yes, correct. You would have to do it in cartesian first and then project it to polar coordinates and then plot it. Probably doable, but indeed not one single API call :(.
Wow, what a journey...
As you can see from the image, I have solved this problem for (at a minimum) my use case. After some statistical education, I concluded that I should plot a tolerance interval (a range where most values fall), rather than a confidence interval (a range likely to contain the mean), but the main article I used as guidance still refers to the generated plot as a "confidence ellipse." Suffice it to say that I don't have the statistical expertise to know the perfect terminology.
You can look at the main function for drawing the ellipse, as well as a plot similar to the image above that makes use of it.
The main issue is that some transformations are easier in cartesian coordinates and others (rotation) are easier in polar coordinates. Unfortunately, the order of the transformations matters to the technique in the article, so following it requires moving between polar and cartesian coordinates more than once.
If you are interested, I believe that it should be possible to generalize this solution and upstream it. I haven't yet written a function to draw the ellipse on cartesian plots, but it should not be difficult now that I've done so for polar plots.
For example, I think we could put this in a trait, and implement it only for
Scatter<f64, f64>andScatterPolar<f64, f64>, and that would cover the majority of use cases. I can't see any way to implement it generically forScatterPolar<Theta, R>, because the only trait bounds onThetaandRareSerialize + Clone + 'static, so they may not even be numeric.@dustypomerleau , wow, nicely done! :)
Thanks for sharing the article and your implementation. I guess, drawing the ellipse on the chartesian should be easier than what you went through.
If you are willing to upstream your part, even if only as an example in the examples/ folder and in the mdBook, that would already be a great addition IMO.
Reacted by Dusty Pomerleau
Thanks for all the time you've been putting into this crate recently.
I would like to plot a confidence interval on a
ScatterPolarplot, using an ellipse:This looks very similar to this example from the book, but it also requires the abilty to rotate the ellipse relative to the layout.
Is it possible to rotate a shape? Am I missing a more obvious solution?