# \[ANN\] First release of \`Curve\_sampling\`

**URL:** https://discuss.ocaml.org/t/ann-first-release-of-curve-sampling/2970
**Category:** Community
**Tags:** announce
**Created:** [November 28, 2018, 2:03pm UTC](https://discuss.ocaml.org/t/ann-first-release-of-curve-sampling/2970 "2018-11-28T14:03:13Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Chris00](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/chris00/32/48_2.png) [@Chris00](https://discuss.ocaml.org/u/Chris00)
#### Post date: [November 28, 2018, 2:03pm UTC](https://discuss.ocaml.org/t/ann-first-release-of-curve-sampling/2970/1 "2018-11-28T14:03:13Z")

</div>

Hi,

It is my pleasure to announce the first r[elease of the package `curve-sampling`](https://github.com/ocaml/opam-repository/pull/13060) which provides adaptive sampling of functions (and more generally parametric curves) so they can be represented graphically with a minimal number of evaluations. [`Curve_sampling`](https://github.com/Chris00/ocaml-curve-sampling) takes the viewpoint that the evaluation function may be costly, so one specifies the number of evaluations one wants. For example, a representation of x ↦ x sin(1/x) with 227 evaluations gives (rendered with Gnuplot but `Curve_sampling` is independent of a rendering engine):  
 ![graph1](https://us1.discourse-cdn.com/flex020/uploads/ocaml/original/2X/0/00b28c02e09b078c3f02189d2f91c96bb64094d7.png)

The chosen evaluation points are displayed on the following graph:  
 ![graph1_p](https://us1.discourse-cdn.com/flex020/uploads/ocaml/original/2X/1/14d53bed52dd3e2d4b531d4a52f0069d0734a4bd.png)

As a comparison, here is the graph produced by Mathematica for the same function (which uses a different procedure which does not allow to limit the number of evaluations, only the recursion depth, here 5, yielding to the evaluation at 227 points):  
 ![Plot%20Points10%20MaxRecursion5%20eval227](https://us1.discourse-cdn.com/flex020/uploads/ocaml/original/2X/5/591067fb2eb769c4b7a4970a46f80d4dcab94ddb.png)

With 389 evaluations (recursion depth of 6 for Mathematica), the graphs become:  
 ![graph2](https://us1.discourse-cdn.com/flex020/uploads/ocaml/original/2X/8/844aa2b5bb58427c3fe65dae3e1b056999e49f35.png)  
 ![graph2_p](https://us1.discourse-cdn.com/flex020/uploads/ocaml/original/2X/9/9ed4e1ef0a5bcba81113ebfd8047b4999b241472.png)  
and  
 ![Plot%20Points10%20MaxRecursion6%20eval389](https://us1.discourse-cdn.com/flex020/uploads/ocaml/original/2X/f/f5a97020bf28240e50bf0a2b031a3c38cc613055.png)

Enjoy the library and, if you have functions that are not sampled well with the current algorithm, do not hesitate to [fill an issue](https://github.com/Chris00/ocaml-curve-sampling/issues).

Have a nice day,  
C.

---

<div class="post-metadata">

### Author: ![n4323](https://avatars.discourse-cdn.com/v4/letter/n/97f17d/32.png) [@n4323](https://discuss.ocaml.org/u/n4323)
#### Post date: [November 28, 2018, 4:56pm UTC](https://discuss.ocaml.org/t/ann-first-release-of-curve-sampling/2970/2 "2018-11-28T16:56:23Z")

</div>

Cool! what do you imagine as a workflow for graphical output? is there a way to feed the sampled points to matplotlib, for example?

---

<div class="post-metadata">

### Author: ![Chris00](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/chris00/32/48_2.png) [@Chris00](https://discuss.ocaml.org/u/Chris00)
#### Post date: [November 28, 2018, 7:32pm UTC](https://discuss.ocaml.org/t/ann-first-release-of-curve-sampling/2970/3 "2018-11-28T19:32:22Z")

</div>

> [@n4323](#):
>
> is there a way to feed the sampled points to matplotlib, for example?

There is `Curve_sampling.to_file` that saves the data to a file as lines of `x y` with blank lines when the curve needs to be interrupted. It can certainly be read from Python. Another possibility would be to use [py](https://github.com/zshipko/ocaml-py) to import the data without using a file — there is `Curve_sampling.to_list` to get it from the sampling but additional exports may be added (a `Seq` export is available on OCaml ≥ 4.07). If you try that latter route, let me know.
