marcharper / python-ternary

:small_red_triangle: Ternary plotting library for python with matplotlib
MIT License
726 stars 156 forks source link

How to make lines smoother or have anti aliasing generics #166

Open Mr-Liu-CUG opened 3 years ago

Mr-Liu-CUG commented 3 years ago

I have some data points that need to be connected into a curve. How can I do that? If the number of points is too many, there will be obvious unevenness, and if the number of points is too few, there will be obvious edges and corners. How to make the line present a smooth curve effect in the triangle? Or anti aliasing? I would appreciate your advice.

maximweb commented 3 years ago

Maybe it helps to smoothen your data, for example using SavGol filter?

Mr-Liu-CUG commented 3 years ago

Maybe it helps to smoothen your data, for example using SavGol filter?

Usually it is to carry on the filter processing to the two-dimensional data, but my triangle chart data is the three-dimensional data, how should carry on the filter operation

maximweb commented 3 years ago

Maybe it helps to smoothen your data, for example using SavGol filter?

Usually it is to carry on the filter processing to the two-dimensional data, but my triangle chart data is the three-dimensional data, how should carry on the filter operation

Lets assume you have 2D data y over x: As long as you are not interested in a derivative but only the data itself, SavGol does not care whether the points are equidistant (see delta parameter in the documentation, which is not required when deriv=0 and the SavGol function has no input for x AND y but only one data array.) So in this case you could just use SavGol over your x and y data arrays individually.

For ternary data (x+y+z=1) I would suggest you use SavGol filter over x, y and z individually.

What could go wrong:

Feel free to post code of a minimal example with your data.

Mr-Liu-CUG commented 3 years ago

Thank you very much for your detailed reply, thank you for giving me ideas