yuzie007 / mpltern

Ternary plots as projections of Matplotlib
https://yuzie007.github.io/mpltern
MIT License
39 stars 2 forks source link

Feature request: Add support for `streamplot` #7

Open saumil-sh opened 3 years ago

saumil-sh commented 3 years ago

Hi, Thank you for writing this package I find it very easy-to-use and handy. I sometimes prefer streamplot over quiver. I was wondering if you could also add this feature. I'd understand if you don't have the time for it. In that case, could you give me some instructions on how to add this feature, I am willing to do it and make a merge request. I suppose it shouldn't be too difficult since quiver and streamplot are not very different.

Thank you again!

Edit: I (naively) tried copying the quiver block and changing it to streamplot at line 757 here https://github.com/yuzie007/mpltern/blob/977d26d624a87d9c74a81aa7e84198bf70ea34a9/mpltern/ternary/_axes.py, which lead to the following error ValueError: 'x' must be strictly increasing.

yuzie007 commented 3 years ago

Thank you so much @SamD97 for your request! I agree with you that streamplot may be reasonable to be implemented. Maybe the reason I did not inherit it from Matplotlib was simply that I am not familiar with the algorithm of streamplot and how it would be in ternary plots. I would like to take a look more seriously to find how to do / what to do. If you're already familiar with the algorithm of streamplot and how it would be in ternary plots, may I also later ask you your thoughts?

saumil-sh commented 3 years ago

Hello @yuzie007, thank you for your reply. I am glad to know that you agree on the addition of streamplot. I'd be happy to discuss whatever I know. So far, I have had limited success with my try using Affine2D().skew() (attached image, also the result I am aiming for using mpltern). I tried being smart and importing the LineCollection to a different subplot with projection='ternary', but matplotlib denied my efforts saying ValueError: Can not reset the axes. You are probably trying to re-use an artist in more than one Axes which is not supported 😅 . image

yuzie007 commented 2 years ago

Thank you @SamD97 for your reply, and sorry for my long silence. The figure looks very cool. We can indeed implement this streamplot style.

It seems presently Matplotlib streamplot is specifically for rectangular grid (although we can probably transform this into the triangular view as you did), while I hope to have the interpolation on the triangular lattice, due to the philosophical reason that in ternary plots all three coordinates should be dealt on an equal footing. Let me kindly give a little time to survey if this is indeed possible. Once I get updates, I would like to let you know again!

Gritbadger commented 9 months ago

I also find this package does not support streamplot, who can help me? and also I try to use ggtern package in R, and plotly package in python, they all do not support streamplot.