歩いたら休め

なんでこんな模様をしているのですか?

【Rust】Rustで数値計算プロジェクトを試す その3

数値計算のプロジェクトでは、結局グラフの形式で出力することも多いと思います。csvで出力して古き良きgnuplotでもいいんですが、Pythonのmatplotlibみたいなのが無いか調べます。

pure Rustのこちらのライブラリを試してみます。

github.com

しかし、こちらのサンプルコードをコンパイルしようとするとエラーが出てしまいます。

extern crate plotlib;
use plotlib::scatter::Scatter;
use plotlib::scatter;
use plotlib::style::{Marker, Point};
use plotlib::view::View;
use plotlib::page::Page;

fn main() {
    // Scatter plots expect a list of pairs
    let data1 = [(-3.0, 2.3), (-1.6, 5.3), (0.3, 0.7), (4.3, -1.4), (6.4, 4.3), (8.5, 3.7)];

    // We create our scatter plot from the data
    let s1 = Scatter::from_slice(&data1)
        .style(scatter::Style::new()
            .marker(Marker::Square) // setting the marker to be a square
            .colour("#DD3355")); // and a custom colour

    // We can plot multiple data sets in the same view
    let data2 = [(-1.4, 2.5), (7.2, -0.3)];
    let s2 = Scatter::from_slice(&data2)
        .style(scatter::Style::new() // uses the default marker
            .colour("#35C788")); // and a different colour

    // The 'view' describes what set of data is drawn
    let v = View::new()
        .add(&s1)
        .add(&s2)
        .x_range(-5., 10.)
        .y_range(-2., 6.)
        .x_label("Some varying variable")
        .y_label("The response of something");

    // A page with a single view is then saved to an SVG file
    Page::single(&v).save("scatter.svg");
}

いくつかエラー出てますが、「どうやら関数が名前空間に存在しない」ような感じのエラーのようです。ただ、実際のコード見てもあるんだよなあ…。

> cargo run
   Compiling duplex-pendulum v0.1.0 (/Users/takeshi/Desktop/projects/duplex-pendulum)
error[E0599]: no function or associated item named `from_slice` found for type `plotlib::scatter::Scatter` in the current scope
  --> src/main.rs:13:14
   |
13 |     let s1 = Scatter::from_slice(&data1)
   |              ^^^^^^^^^^^^^^^^^^^ function or associated item not found in `plotlib::scatter::Scatter`

また、私も ~/.gitconfig の設定の問題で、↓の問題が起こってcratesを追加できなくなってしまっていました。これは解決したのですが、いろいろ設定いじってたらgithubの認証が利用できなくなる問題が…。後でなんとかしよう。

github.com