GithubHelp home page GithubHelp logo

Comments (7)

38 avatar 38 commented on August 29, 2024

I don't know if you realized this, series is just a iterator of elements. Basically bar chart can be done with

     ctx.draw_series( 
             data.map(|(bucket, value)| {
                    let rect = Rectangle::new([(bucket - 1, 0), (bucket, value)], BLUE.filled());
                    rect.margin(0, 0, 5, 5); 
                    rect
            })
     );

And of course you can control the color. I am not very satisfy with current implementation of histogram, and I am thinking about some better solution as well. If you have any thoughts, please let me know :)

For your second question, this also can be done by implementing a wrapper for ranged value and you can control what key point you want to emit. The key trait to implement is called Ranged, see docs at https://docs.rs/plotters/0.2.11/plotters/coord/trait.Ranged.html.

The logarithmic coordinate is supported in this way, please see code at https://github.com/38/plotters/blob/master/src/coord/logarithmic.rs.

And of course both suggest make sense to me and please let me think how to make built-in support for these.

from plotters.

TatriX avatar TatriX commented on August 29, 2024

It's not yet clear to me what can passed to draw_series. Currently my brain stops at E: Drawable<DB> from here.
I guess passing some kind of data structure should do the trick:

draw_series(LineSeries::new(data.map(|x, y| Point{x, y, color: Some(rand_color()) }), &RED))

So color defaults to RED but can be overriden by individual data point.

from plotters.

38 avatar 38 commented on August 29, 2024

Hmm, draw_series accepts anything can be converted into a iterator of elements.

An element is actually combination of two trait, one is PointCollection which holds the vertices another one is Drawable<DB> means once the coordinate mapping is done, it can be drawn on to the specific backend.

And anything under element module should be ready to pass into draw_series.

The element system is a little bit undocumented unfortunately, the only doc I have is https://docs.rs/plotters/0.2.11/plotters/element/index.html

from plotters.

38 avatar 38 commented on August 29, 2024

A quick update on this. I changed the histogram API which allows you to passing a closure that retutrns style based on the values.

Check here for details, let me know if this works for you:)

https://github.com/38/plotters/blob/8e99cdd69b9708f571c46d07161048dbcfe344a5/src/series/histogram.rs#L59

from plotters.

38 avatar 38 commented on August 29, 2024

Also, now you can use code like

.build_ranged((0..100).group_by(7), 10..20)?

to make the key point a multiply of 7

from plotters.

TatriX avatar TatriX commented on August 29, 2024

This looks amazing! Will try soon.
BTW, do you have any plans on making range being set in an automatic fashion?
Currently I need to collect data to for example into Vec, then find min/max values and only then I can draw series.

from plotters.

TatriX avatar TatriX commented on August 29, 2024

Yep, both features work like a charm, thanks!

from plotters.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.