loony-bean / textplots-rs

Terminal plotting library for Rust
240 stars 24 forks source link

Scatter plots #11

Closed Skeletonxf closed 4 years ago

Skeletonxf commented 4 years ago

Hi

I've started using this library in some test code I've been writing and I've reached a few places where I would like to be able to create a scatter plot.

Would it be possible/easy to implement scatter plots into this library?

Thanks

loony-bean commented 4 years ago

Hi @Skeletonxf! I think it's a good idea.

Do you think it is something you would like to do? (no problem if you wouldn't, I will make it) I think you could add a new shape like Shape::Points and then let the compiler guide you.

Skeletonxf commented 4 years ago

I don't really understand the library code so if you could do it that would be great

loony-bean commented 4 years ago

Alright! Just published 0.5.0, pls check if it has what you need.

Skeletonxf commented 4 years ago

Thanks

It's working quite well though there are two minor issues

It's a bit odd calling chart.lineplot(Shape::Points(...));

as a scatter plot isn't exactly a lineplot

Secondly if I supply a list of points containing only one (f32, f32) pair the point isn't drawn, I think this is because of the line at 292 https://github.com/loony-bean/textplots-rs/blob/a3262a9d28ad965fa5b09373126c3613c1f82094/src/lib.rs#L290-L293 that seems to assume there is a second pair of points.

loony-bean commented 4 years ago

You are definitely right about lineplot 😄but the interface is not final, and I thought it's not a big deal.

The second one is a bug. I'll fix it, thanks for notice!