MCPcopy Create free account
hub / github.com/alandefreitas/matplotplusplus / matrix_data_string

Method matrix_data_string

source/matplot/axes_objects/matrix.cpp:129–274  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

127 }
128
129 std::string matrix::matrix_data_string() {
130 // single matrix
131 auto &matrix_ = matrices_[0];
132
133 // calculate min/max row/cols if normalizing
134 std::vector<double> value_max;
135 std::vector<double> value_min;
136 if (normalization_ == color_normalization::columns) {
137 value_max.resize(matrix_[0].size());
138 value_min.resize(matrix_[0].size());
139 for (size_t i = 0; i < matrix_[0].size(); ++i) {
140 value_max[i] = matrix_[0][i];
141 value_min[i] = matrix_[0][i];
142 for (size_t j = 0; j < matrix_.size(); ++j) {
143 if (matrix_[j][i] > value_max[i]) {
144 value_max[i] = matrix_[j][i];
145 }
146 if (matrix_[j][i] < value_min[i]) {
147 value_min[i] = matrix_[j][i];
148 }
149 }
150 }
151 } else if (normalization_ == color_normalization::rows) {
152 value_max.resize(matrix_.size());
153 value_min.resize(matrix_.size());
154 for (size_t i = 0; i < matrix_.size(); ++i) {
155 value_max[i] = matrix_[i][0];
156 value_min[i] = matrix_[i][0];
157 for (size_t j = 0; j < matrix_[0].size(); ++j) {
158 if (matrix_[i][j] > value_max[i]) {
159 value_max[i] = matrix_[i][j];
160 }
161 if (matrix_[i][j] < value_min[i]) {
162 value_min[i] = matrix_[i][j];
163 }
164 }
165 }
166 }
167
168 // stream matrix
169 std::stringstream ss;
170 ss.precision(10);
171 ss << std::fixed;
172 double x_width_ = x_width();
173 double y_width_ = y_width();
174 const auto &[cb_min, cb_max] = parent_->color_box_range();
175 bool use_cb_range = cb_min != cb_max;
176 for (size_t i = 0; i < matrix_.size(); ++i) {
177 for (size_t j = 0; j < matrix_[i].size(); ++j) {
178 // z will be normalized
179 double z = matrix_[i][j];
180 switch (normalization_) {
181 case color_normalization::none:
182 break;
183 case color_normalization::columns:
184 z -= value_min[j];
185 z /= value_max[j] - value_min[j];
186 break;

Callers

nothing calls this directly

Calls 5

x_widthFunction · 0.85
y_widthFunction · 0.85
color_box_rangeMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected