Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
matiu2 wants to merge4 commits intoplotters-rs:master
base:master
Choose a base branch
Loading
frommatiu2:master

Conversation

matiu2
Copy link

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
Copy link

codecovbot commentedFeb 12, 2020
edited
Loading

Codecov Report

Merging#111 (a06f868) intomaster (dee7727) willdecrease coverage by1.37%.
The diff coverage is13.63%.

Impacted file tree graph

@@            Coverage Diff             @@##           master     #111      +/-   ##==========================================- Coverage   67.48%   66.11%   -1.38%==========================================  Files          53       53                Lines        5160     5152       -8     ==========================================- Hits         3482     3406      -76- Misses       1678     1746      +68
Impacted FilesCoverage Δ
src/coord/category.rs62.06% <13.63%> (-16.72%)⬇️
src/coord/logarithmic.rs0.00% <0.00%> (-60.00%)⬇️
src/style/font/ttf.rs72.52% <0.00%> (-7.91%)⬇️
src/series/line_series.rs71.87% <0.00%> (-4.60%)⬇️
src/drawing/rasterizer/line.rs67.34% <0.00%> (-3.63%)⬇️
src/element/boxplot.rs77.77% <0.00%> (-2.51%)⬇️
src/drawing/backend.rs58.82% <0.00%> (-2.36%)⬇️
src/style/font/font_desc.rs47.67% <0.00%> (-2.33%)⬇️
src/drawing/backend_impl/bitmap.rs83.21% <0.00%> (-2.32%)⬇️
src/drawing/backend_impl/svg.rs73.47% <0.00%> (-2.07%)⬇️
... and21 more

Continue to review full report at Codecov.

Legend -Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing data
Powered byCodecov. Last updatedee7727...12f8430. Read thecomment docs.

@matiu2matiu2force-pushed themaster branch 2 times, most recently from8d20955 toa06f868CompareFebruary 12, 2020 13:54
@38
Copy link
Member

38 commentedFeb 12, 2020

Thanks for the PR.

I think the PR looks good to me. I am currently working on a new major release shipping with discrete coordinate trait refactor#89 and slice coordinate support#104 . With those changes,Category will be removed and slice will be able to use as coordinate spec directly. (Actually the discrete coordinate trait has been messed up for a long time)

One of the related example on this change would behttps://github.com/38/plotters/blob/v0.3-pre/examples/nested_coord.rs Though it's not really the bar chart but roughly shows how things work.

And here's a quick example use v0.3:

use plotters_bitmap::BitMapBackend;use plotters::prelude::*;fnmain(){letmut root =BitMapBackend::new("out.png",(800,600)).into_drawing_area();    root.fill(&WHITE);let data =["a","b","c","d","e"];letmut chart =ChartBuilder::on(&root).set_all_label_area_size(30).build_ranged((&data[..]).into_centric(),0..10).unwrap();    chart.configure_mesh().disable_mesh().draw();let hist =Histogram::vertical(&chart).data(vec![(&"a",5),(&"b",2),(&"c",8),(&"d",7),(&"e",4)]).margin(15);    chart.draw_series(hist);}

image

So if my understand is right, it seems this PR will provide the exactly same feature.

Sorry for the confusion. Thanks again for the contribution!

Cheers!

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@matiu2@38@pelekhay

[8]ページ先頭

©2009-2025 Movatter.jp