GithubHelp home page GithubHelp logo

Comments (19)

38 avatar 38 commented on July 25, 2024

Hi @serzhiio ,

I don't quite understand what do you mean by internally nested.

My understanding is you need two chart, the X axis is aligned and X axis is rendered in the middle of the upper chart and bottom chart.

If this is what you mean, that you should do is

  1. vertically split the parent drawing area into two
  2. build chart context on two drawing area with same X axis specification and different Y axis
  3. make sure the upper chart is configured with X axis label area size > 0 and lower one is 0

Here's the sample code

    let (upper, lower) = root_area.split_vertically(300);

    let mut upper_chart = ChartBuilder::on(&upper)
        .x_label_area_size(40)
        .y_label_area_size(40)
        .build_ranged(0..100, 0..100)?;
    let mut lower_chart = ChartBuilder::on(&lower)
        .y_label_area_size(40)
        .build_ranged(0..100, -1.0f32..1.0f32)?;

    upper_chart.configure_mesh().disable_x_mesh().disable_y_mesh().draw()?;
    lower_chart.configure_mesh().disable_x_mesh().disable_y_mesh().draw()?;

And here's what it looks like

image

Hope this is helpful

from plotters.

serzhiio avatar serzhiio commented on July 25, 2024

from plotters.

38 avatar 38 commented on July 25, 2024

Or you mean a chart with an additional Y axis ?

from plotters.

serzhiio avatar serzhiio commented on July 25, 2024

from plotters.

38 avatar 38 commented on July 25, 2024

Ah, I see, this is a feature I am currently working on. It's available on the master branch currently.

The sample code like this.

    let mut chart = ChartBuilder::on(&root_area)
        .x_label_area_size(40)
        .y_label_area_size(40)
        .right_y_label_area_size(40)
        .build_ranged(0..100, 0..100)?
        .set_secondary_coord(0..100, -1.0f32..1.0f32);

    chart.configure_mesh().disable_x_mesh().disable_y_mesh().draw()?;
    chart.configure_secondary_axes().draw()?;

And it will produce

image

from plotters.

serzhiio avatar serzhiio commented on July 25, 2024

from plotters.

38 avatar 38 commented on July 25, 2024

Ah, I see, this is a feature request then. But I need to think about how to handle this reasonably.

Currently, the hacky way to do that is we can

  1. build the bigger chart
  2. shrink the drawing area to bottom 20% of the orignial area
  3. make the y axis on the right
  4. draw it

image

    let mut chart = ChartBuilder::on(&root_area)
        .x_label_area_size(40)
        .y_label_area_size(40)
        .build_ranged(0..100, 0..100)?;

    chart.configure_mesh().disable_x_mesh().disable_y_mesh().draw()?;

    let (_, smaller_chart) = chart.plotting_area().strip_coord_spec().split_vertically(300);
    
    let mut chart = ChartBuilder::on(&smaller_chart)
        .right_y_label_area_size(40)
        .build_ranged(0..100, -1.0f32..1.0f32)?;

    chart.configure_mesh().disable_x_mesh().disable_y_mesh().draw()?;

from plotters.

serzhiio avatar serzhiio commented on July 25, 2024

from plotters.

38 avatar 38 commented on July 25, 2024

Just implemented the feature. You should be abe to use the following code for this purpose.

    let mut chart = ChartBuilder::on(&root_area)
        .x_label_area_size(40)
        .y_label_area_size(40)
        .right_y_label_area_size(40)
        .build_ranged(0..100, 0..100)?
        .set_secondary_coord(0..100, make_partial_axis(0f32..10f32, 0.0..0.3).unwrap());

    chart.configure_mesh().disable_x_mesh().disable_y_mesh().draw()?;
    chart.configure_secondary_axes().y_labels(30).draw()?;

image

from plotters.

serzhiio avatar serzhiio commented on July 25, 2024

Great, but can i set the axis to overlay working surface? Now all axes are out of plot.
P.S.: It would be nice feature for any axis.

from plotters.

38 avatar 38 commented on July 25, 2024

You mean the label ? Currently not, but I am going to expose the API allows to adjust the distance from the axis to the label. After that you should able to set the distance to a negative value to make that happen. :)

from plotters.

38 avatar 38 commented on July 25, 2024

Hi @serzhiio , just want to have a follow up on how things going. And I am going to close this issue and create another one tracking the feature that makes the axis inside the plot.

Feel free to reopen it. And let me know if you have any other questions. :)

from plotters.

serzhiio avatar serzhiio commented on July 25, 2024

Do we really need to set y-axis range for partial axis?
.set_secondary_coord(0..100, make_partial_axis(0f32..10f32, 0.0..0.3).unwrap());
Seems y-axis is already exists for secondary coord?

from plotters.

serzhiio avatar serzhiio commented on July 25, 2024

... and how to draw chart using secondary axis?

from plotters.

38 avatar 38 commented on July 25, 2024

Do we really need to set y-axis range for partial axis?
.set_secondary_coord(0..100, make_partial_axis(0f32..10f32, 0.0..0.3).unwrap());
Seems y-axis is already exists for secondary coord?

I am not sure what you mean. But this make_partial_axis gives you an ability to make an axis which only 30% of the entire range is shown on the axis.

... and how to draw chart using secondary axis?

And for this one, you should be able to use this: https://docs.rs/plotters/0.2.7/plotters/chart/struct.DualCoordChartContext.html#method.draw_secondary_series

from plotters.

serzhiio avatar serzhiio commented on July 25, 2024

Thx, already managed it.

from plotters.

serzhiio avatar serzhiio commented on July 25, 2024

With this configuration i cant draw second axis y-labels. They are just not printing out.

    let mut chart = ChartBuilder::on(&root_area)
        .x_label_area_size(40)
        .y_label_area_size(40)
        .right_y_label_area_size(40)
        .build_ranged(0..100, 0..100)?
        .set_secondary_coord(0..100, make_partial_axis(0f32..10f32, 0.0..0.3).unwrap());

    chart.configure_mesh().disable_x_mesh().disable_y_mesh().draw()?;
    chart.configure_secondary_axes().y_labels(30).draw()?;

from plotters.

serzhiio avatar serzhiio commented on July 25, 2024

Looks like the problem for is that there is no .label_style() mathod for secondary axes.

from plotters.

38 avatar 38 commented on July 25, 2024

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.