Support for bar graphs. Helps with issue #98 by matiu2 · Pull Request #111 · plotters-rs/plotters · GitHub
Skip to content

Support for bar graphs. Helps with issue #98#111

Open
matiu2 wants to merge 4 commits into
plotters-rs:masterfrom
matiu2:master
Open

Support for bar graphs. Helps with issue #98#111
matiu2 wants to merge 4 commits into
plotters-rs:masterfrom
matiu2:master

Conversation

@matiu2

@matiu2 matiu2 commented Feb 12, 2020

Copy link
Copy Markdown

I'll admit it's not a very elegant pull request and won't be offended if you completely redo it.

It allows you to use Category axis in histograms by making them implement PartialEq, Eq, Hash, and DiscreteRanged.

When it implements DiscreteRanged, it just wraps around the ends of the category.

Rough usage example:

        let x_labels = vec!["< 1", "1-3", "3-6", "6-9", "> 9"];
        let mut data: Vec<usize> = Vec::with_capacity(x_labels.len());
        data.push(days.iter().take_while(|&&days| days < 1).count() as usize);
        data.push(days.iter().skip_while(|&&days| days < 1).take_while(|&&days| days < 3).count());
        data.push(days.iter().skip_while(|&&days| days < 3).take_while(|&&days| days < 6).count());
        data.push(days.iter().skip_while(|&&days| days < 6).take_while(|&&days| days < 9).count());
        let max_tickets: usize = *data.iter().max().unwrap();

        chart
            .configure_mesh()
            // Don't show a grid for the x axis
            .disable_x_mesh()
            // Make the y axis grid be light gray
            .line_style_1(&WHITE.mix(0.3))
            .x_desc("Biggest gap in days")
            .y_desc("Interaction Count")
            .axis_desc_style(("sans-serif", 15).into_font())
            .draw()?;

        chart.draw_series(
            Histogram::vertical(&chart)
                .style(RED.mix(0.5).filled())
                .data(x_labels.iter().flat_map(|x| category.get(x)).zip(data)),
        )?;

@codecov

codecov Bot commented Feb 12, 2020

Copy link
Copy Markdown

@matiu2 matiu2 force-pushed the master branch 2 times, most recently from 8d20955 to a06f868 Compare February 12, 2020 13:54
@38

38 commented Feb 12, 2020

Copy link
Copy Markdown
Member

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

Successfully merging this pull request may close these issues.

3 participants