• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use plotters::prelude::*;
2 
3 use chrono::{TimeZone, Utc};
4 
5 use std::error::Error;
6 
main() -> Result<(), Box<dyn Error>>7 fn main() -> Result<(), Box<dyn Error>> {
8     let root =
9         BitMapBackend::new("plotters-doc-data/slc-temp.png", (1024, 768)).into_drawing_area();
10 
11     root.fill(&WHITE)?;
12 
13     let mut chart = ChartBuilder::on(&root)
14         .margin(10)
15         .caption(
16             "Monthly Average Temperate in Salt Lake City, UT",
17             ("sans-serif", 40),
18         )
19         .set_label_area_size(LabelAreaPosition::Left, 60)
20         .set_label_area_size(LabelAreaPosition::Right, 60)
21         .set_label_area_size(LabelAreaPosition::Bottom, 40)
22         .build_cartesian_2d(
23             (Utc.ymd(2010, 1, 1)..Utc.ymd(2018, 12, 1)).monthly(),
24             14.0..104.0,
25         )?
26         .set_secondary_coord(
27             (Utc.ymd(2010, 1, 1)..Utc.ymd(2018, 12, 1)).monthly(),
28             -10.0..40.0,
29         );
30 
31     chart
32         .configure_mesh()
33         .disable_x_mesh()
34         .disable_y_mesh()
35         .x_labels(30)
36         .y_desc("Average Temp (F)")
37         .draw()?;
38     chart
39         .configure_secondary_axes()
40         .y_desc("Average Temp (C)")
41         .draw()?;
42 
43     chart.draw_series(LineSeries::new(
44         DATA.iter().map(|(y, m, t)| (Utc.ymd(*y, *m, 1), *t)),
45         &BLUE,
46     ))?;
47 
48     chart.draw_series(
49         DATA.iter()
50             .map(|(y, m, t)| Circle::new((Utc.ymd(*y, *m, 1), *t), 3, BLUE.filled())),
51     )?;
52 
53     Ok(())
54 }
55 
56 const DATA: [(i32, u32, f64); 12 * 9] = [
57     (2010, 1, 32.4),
58     (2010, 2, 37.5),
59     (2010, 3, 44.5),
60     (2010, 4, 50.3),
61     (2010, 5, 55.0),
62     (2010, 6, 70.0),
63     (2010, 7, 78.7),
64     (2010, 8, 76.5),
65     (2010, 9, 68.9),
66     (2010, 10, 56.3),
67     (2010, 11, 40.3),
68     (2010, 12, 36.5),
69     (2011, 1, 28.8),
70     (2011, 2, 35.1),
71     (2011, 3, 45.5),
72     (2011, 4, 48.9),
73     (2011, 5, 55.1),
74     (2011, 6, 68.8),
75     (2011, 7, 77.9),
76     (2011, 8, 78.4),
77     (2011, 9, 68.2),
78     (2011, 10, 55.0),
79     (2011, 11, 41.5),
80     (2011, 12, 31.0),
81     (2012, 1, 35.6),
82     (2012, 2, 38.1),
83     (2012, 3, 49.1),
84     (2012, 4, 56.1),
85     (2012, 5, 63.4),
86     (2012, 6, 73.0),
87     (2012, 7, 79.0),
88     (2012, 8, 79.0),
89     (2012, 9, 68.8),
90     (2012, 10, 54.9),
91     (2012, 11, 45.2),
92     (2012, 12, 34.9),
93     (2013, 1, 19.7),
94     (2013, 2, 31.1),
95     (2013, 3, 46.2),
96     (2013, 4, 49.8),
97     (2013, 5, 61.3),
98     (2013, 6, 73.3),
99     (2013, 7, 80.3),
100     (2013, 8, 77.2),
101     (2013, 9, 68.3),
102     (2013, 10, 52.0),
103     (2013, 11, 43.2),
104     (2013, 12, 25.7),
105     (2014, 1, 31.5),
106     (2014, 2, 39.3),
107     (2014, 3, 46.4),
108     (2014, 4, 52.5),
109     (2014, 5, 63.0),
110     (2014, 6, 71.3),
111     (2014, 7, 81.0),
112     (2014, 8, 75.3),
113     (2014, 9, 70.0),
114     (2014, 10, 58.6),
115     (2014, 11, 42.1),
116     (2014, 12, 38.0),
117     (2015, 1, 35.3),
118     (2015, 2, 45.2),
119     (2015, 3, 50.9),
120     (2015, 4, 54.3),
121     (2015, 5, 60.5),
122     (2015, 6, 77.1),
123     (2015, 7, 76.2),
124     (2015, 8, 77.3),
125     (2015, 9, 70.4),
126     (2015, 10, 60.6),
127     (2015, 11, 40.9),
128     (2015, 12, 32.4),
129     (2016, 1, 31.5),
130     (2016, 2, 35.1),
131     (2016, 3, 49.1),
132     (2016, 4, 55.1),
133     (2016, 5, 60.9),
134     (2016, 6, 76.9),
135     (2016, 7, 80.0),
136     (2016, 8, 77.0),
137     (2016, 9, 67.1),
138     (2016, 10, 59.1),
139     (2016, 11, 47.4),
140     (2016, 12, 31.8),
141     (2017, 1, 29.4),
142     (2017, 2, 42.4),
143     (2017, 3, 51.7),
144     (2017, 4, 51.7),
145     (2017, 5, 62.5),
146     (2017, 6, 74.8),
147     (2017, 7, 81.3),
148     (2017, 8, 78.1),
149     (2017, 9, 65.7),
150     (2017, 10, 52.5),
151     (2017, 11, 49.0),
152     (2017, 12, 34.4),
153     (2018, 1, 38.1),
154     (2018, 2, 37.5),
155     (2018, 3, 45.4),
156     (2018, 4, 54.6),
157     (2018, 5, 64.0),
158     (2018, 6, 74.9),
159     (2018, 7, 82.5),
160     (2018, 8, 78.1),
161     (2018, 9, 71.9),
162     (2018, 10, 53.2),
163     (2018, 11, 39.7),
164     (2018, 12, 33.6),
165 ];
166 #[test]
entry_point()167 fn entry_point() {
168     main().unwrap()
169 }
170