wiseaidev / rust-data-analysis

Rust for data analysis encyclopedia (WIP).
Apache License 2.0
338 stars 38 forks source link

[🐛 Bug]: Line plots with sharp edges. #9

Closed wiseaidev closed 1 year ago

wiseaidev commented 1 year ago

👶 Getting Started Please search the history to see if an issue already exists for the same problem.

📝 Describe the bug The line plots are not very smooth because of the small sample size for each example. To make the line smooth, we can increase the sample size. For integer numbers, this is easy to fix. However, the problem exists for floating point numbers.

🕹 Steps to reproduce

  1. Go to 5-probability-theory-tutorial.ipynb
  2. Notice how the line plots are not very smooth because of the small sample size.

😯 Current behavior Line plots with sharp edges.

1 SOSTdPChdFayMGt7sJw1Rw

🤔 Expected behavior Increase the sample size to ~ 100 data points to make the line connecting the points smooth.

🔦 Additional context You can use ndarray/linspace method. However, this will add a new dependency. If you can come up with a native Rust implementation, it would be better. Note that for integer numbers, there is no problem, the problem only exists for floating-point numbers.

wiseaidev commented 1 year ago

I've just stumbled upon a neat solution to tackle this problem. Here's an approach we can take to control the step size:

let mut trials: Vec<f64> = (0..100).map(|x| x as f64 / 100.0).collect();

First, we create a vector of integers ranging from 0 to 100, incrementing by 1 ([0, 1, 2, 3...]). Then, we divide each number by 100 to convert the range into [0.0 .. 1.0], giving us 100 evenly spaced points. We now have a step size of 0.01.