Comments (19)
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
- vertically split the parent drawing area into two
- build chart context on two drawing area with same X axis specification and different Y axis
- 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
Hope this is helpful
from plotters.
from plotters.
Or you mean a chart with an additional Y axis ?
from plotters.
from plotters.
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
from plotters.
from plotters.
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
- build the bigger chart
- shrink the drawing area to bottom 20% of the orignial area
- make the y axis on the right
- draw it
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.
from plotters.
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()?;
from plotters.
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.
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.
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.
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.
... and how to draw chart using secondary axis?
from plotters.
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.
Thx, already managed it.
from plotters.
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.
Looks like the problem for is that there is no .label_style() mathod for secondary axes.
from plotters.
from plotters.
Related Issues (20)
- Need to update `font-kit` due to `stdsimd` changes HOT 4
- [BUG] LineSeries and draw_series go out of the image scope if stroke_width > 1
- Y labels are not aligned HOT 1
- [BUG] Rotated labels overlap with the chart HOT 1
- Ability to save figures in the same way you can in rust in a notebook environment. HOT 3
- [BUG] currently nightly compiler cannot build plotters due to bug in pathfinder (simd) HOT 11
- [BUG] Even your own Examples doesn't work HOT 3
- [BUG] Drawing series can hang under certain conditions HOT 7
- [BUG] Can't outline/stroke polygon for svg HOT 1
- [BUG] example crash under centos 7.5 HOT 1
- [BUG] plotters-canvas build error
- plotters v0.3.5 has RUSTSEC-2023-0020 from font-kit v0.11.0 HOT 2
- [BUG] titled function draw text position error when generating PNG file HOT 3
- [BUG] unsafe preconditions violated HOT 12
- default font size?
- [BUG] Spacing between words removed HOT 1
- Step charts
- [BUG] 'static lifetime requirement for `ChartContext`
- pie RGBAcolor
- Warning due to use of deprecated default_features HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from plotters.