Skip to content

Commit 3c81acc

Browse files
Fix large numbers and add timestamp support (#273)
Fix large numbers and add timestamp support
1 parent e84b6a9 commit 3c81acc

21 files changed

+134
-31
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ out
1616
.idea
1717
codealike.json
1818
.vs
19+
.vscode
1920
CMakeLists.txt.user
2021
CMakeSettings.json
2122
gh-md-toc

source/matplot/axes_objects/bars.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ namespace matplot {
143143

144144
std::string bars::data_string() {
145145
std::stringstream ss;
146+
ss.precision(5);
147+
ss << std::fixed;
146148
double m = x_minimum_difference();
147149
double cw = cluster_width();
148150
for (size_t bar_group = 0; bar_group < ys_.size(); ++bar_group) {

source/matplot/axes_objects/box_chart.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ namespace matplot {
127127
}
128128
std::vector<double> unique_groups = unique(x_data_);
129129
std::stringstream ss;
130+
ss.precision(5);
131+
ss << std::fixed;
130132
// for each group
131133
for (size_t i = 0; i < unique_groups.size(); ++i) {
132134
// for each point

source/matplot/axes_objects/circles.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ namespace matplot {
4545

4646
std::string circles::data_string() {
4747
std::stringstream ss;
48+
ss.precision(5);
49+
ss << std::fixed;
4850
for (size_t i = 0; i < x_.size(); ++i) {
4951
auto value_or_default = [](const std::vector<double> &v,
5052
size_t index, double default_value) {

source/matplot/axes_objects/contours.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ namespace matplot {
5050
double contour_max_level = *max_it;
5151

5252
std::stringstream ss;
53+
ss.precision(5);
54+
ss << std::fixed;
5355
if (filled_) {
5456
auto [lower_levels, upper_levels] = get_lowers_and_uppers();
5557
// Command for background filled curve
@@ -413,7 +415,8 @@ namespace matplot {
413415
_levels = levels_;
414416

415417
// Extend minimum beyond zmin (for filled plots)
416-
const bool log = parent_->z_axis().scale() == axis_type::axis_scale::log;
418+
const bool log =
419+
parent_->z_axis().scale() == axis_type::axis_scale::log;
417420
if (extend_ == extend_option::both || extend_ == extend_option::min) {
418421
double lower = log ? 1e-250 : -1e250;
419422
_levels.insert(_levels.begin(), lower);
@@ -475,6 +478,8 @@ namespace matplot {
475478
double zmin = *min_level_it;
476479

477480
std::stringstream ss;
481+
ss.precision(5);
482+
ss << std::fixed;
478483
for (size_t i = 0; i < lines_.size(); ++i) {
479484
if (i != 0) {
480485
ss << ",";
@@ -766,6 +771,8 @@ namespace matplot {
766771
auto [lower_levels, upper_levels] = get_lowers_and_uppers();
767772

768773
std::stringstream ss;
774+
ss.precision(5);
775+
ss << std::fixed;
769776
if (filled_) {
770777
// Plot the line segments
771778
// Create one filled curve for each segment of a contour.
@@ -1024,7 +1031,7 @@ namespace matplot {
10241031
// nans at end of the underlying storage)
10251032
while (j + 1 < lines_[i].first.size() &&
10261033
is_separator(lines_[i].first[j + 1],
1027-
lines_[i].second[j + 1])) {
1034+
lines_[i].second[j + 1])) {
10281035
++j;
10291036
}
10301037
// Include an empty line to indicate this polygon or line

source/matplot/axes_objects/error_bar.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ namespace matplot {
7979
const bool has_x_bar = !x_negative_delta_.empty();
8080
const bool has_xy_bar = has_y_bar && has_x_bar;
8181
std::stringstream ss;
82+
ss.precision(5);
83+
ss << std::fixed;
8284
if (has_xy_bar) {
8385
for (size_t i = 0; i < y_data_.size(); ++i) {
8486
ss << " " << x_data_[i] << " " << y_data_[i] << " "

source/matplot/axes_objects/filled_area.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ namespace matplot {
5858

5959
std::string filled_area::data_string() {
6060
std::stringstream ss;
61+
ss.precision(5);
62+
ss << std::fixed;
6163

6264
std::vector<double> stacked_data;
6365
if (!stacked_) {

source/matplot/axes_objects/histogram.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ namespace matplot {
5555
std::string histogram::plot_string() {
5656
maybe_update_face_color();
5757
std::stringstream ss;
58+
ss.precision(5);
59+
ss << std::fixed;
5860
if (!is_polar()) {
5961
if (!stairs_only_) {
6062
ss << " '-' with boxes fillstyle solid";
@@ -87,6 +89,8 @@ namespace matplot {
8789
std::string histogram::data_string() {
8890
make_sure_data_is_preprocessed();
8991
std::stringstream ss;
92+
ss.precision(5);
93+
ss << std::fixed;
9094
if (!is_polar()) {
9195
for (size_t i = 0; i < values_.size(); ++i) {
9296
// <box center> <box height> <box width>
@@ -517,7 +521,8 @@ namespace matplot {
517521
case binning_algorithm::sqrt:
518522
return sqrt_rule(data, minx, maxx, hard_limits);
519523
}
520-
throw std::logic_error("histogram::histrogram_edges: could not find the binning algorithm");
524+
throw std::logic_error("histogram::histrogram_edges: could not find "
525+
"the binning algorithm");
521526
}
522527

523528
std::vector<size_t>

source/matplot/axes_objects/labels.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ namespace matplot {
9898
font_size_factor = (xrange_increase + yrange_increase) / 2.;
9999
}
100100
std::stringstream ss;
101+
ss.precision(5);
102+
ss << std::fixed;
101103
const bool custom_sizes = !sizes_.empty();
102104
const bool custom_colors = !colors_.empty();
103105
for (size_t i = 0; i < labels_.size(); ++i) {

source/matplot/axes_objects/line.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ namespace matplot {
163163
const bool x_is_manual = !x_data_.empty();
164164

165165
std::stringstream ss;
166+
ss.precision(5);
167+
ss << std::fixed;
166168
for (const auto &style : styles_to_plot()) {
167169
if (visible_) {
168170
const bool data_is_for_markers =
@@ -509,7 +511,7 @@ namespace matplot {
509511
void line::run_draw_commands() {
510512
// ask axes to draw the line
511513
maybe_update_line_spec();
512-
parent_->draw_path(x_data_,y_data_,line_spec_.color());
514+
parent_->draw_path(x_data_, y_data_, line_spec_.color());
513515
}
514516

515517
} // namespace matplot

0 commit comments

Comments
 (0)