Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String labels for xtic #35

Closed
bonorumetmalorum opened this issue Feb 23, 2019 · 3 comments
Closed

String labels for xtic #35

bonorumetmalorum opened this issue Feb 23, 2019 · 3 comments

Comments

@bonorumetmalorum
Copy link

I was creating a bar chart using this library but found that it would not allow for strings to be attached to xtics. If this could be added it would be immensely useful for creating bar charts.

@SiegeLord
Copy link
Owner

You can do this:

let mut fg = Figure::new();
c.set_term(&mut fg);

fg.axes2d()
    .boxes(&[1., 2., 3.], &[1., 2., 3.], &[Color("gray"), BorderColor("black")])
    .set_x_ticks_custom(
        vec![
            Major(1. as f32, Fix("A".into())),
            Major(2. as f32, Fix("B".into())),
            Major(3. as f32, Fix("C".into()))
        ],
        &[],
        &[],
    )
    .set_y_range(Fix(0.0), Auto);
fg.show();

to get:

image

@SiegeLord
Copy link
Owner

SiegeLord commented Feb 23, 2019

Or, if your have an array of labels:

let mut fg = Figure::new();
c.set_term(&mut fg);

let x = [1., 2., 3.];
let y = [1., 2., 3.];
let l = ["A", "B", "C"];

fg.axes2d()
    .boxes(&x, &y, &[Color("gray"), BorderColor("black")])
    .set_x_ticks_custom(
        x.iter().zip(&l).map(|(&x, &l)| Major(x as f32, Fix(l.into()))),
        &[],
        &[],
    )
    .set_y_range(Fix(0.0), Auto);
fg.show();

@bonorumetmalorum
Copy link
Author

Thank you! this helped a lot 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants