8000 remove support for named_plot (obsolete), see message 4 commits earlier · Cryoris/matplotlib-cpp@7c1a3ba · GitHub
[go: up one dir, main page]

Skip to content

Commit 7c1a3ba

Browse files
committed
remove support for named_plot (obsolete), see message 4 commits earlier
1 parent f872d23 commit 7c1a3ba

File tree

5 files changed

+99
-155
lines changed

5 files changed

+99
-155
lines changed

examples/animation.cpp

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,35 @@
11
#define _USE_MATH_DEFINES
2-
#include <cmath>
32
#include "../matplotlibcpp.h"
3+
#include <cmath>
44

55
namespace plt = matplotlibcpp;
66

7-
int main()
8-
{
9-
int n = 1000;
10-
std::vector<double> x, y, z;
7+
int main() {
8+
int n = 1000;
9+
std::vector<double> x, y, z;
1110

12-
for(int i=0; i<n; i++) {
13-
x.push_back(i*i);
14-
y.push_back(sin(2*M_PI*i/360.0));
15-
z.push_back(log(i));
11+
for (int i = 0; i < n; i++) {
12+
x.push_back(i * i);
13+
y.push_back(sin(2 * M_PI * i / 360.0));
14+
z.push_back(log(i));
1615

17-
if (i % 10 == 0) {
18-
// Clear previous plot
19-
plt::clf();
20-
// Plot line from given x and y data. Color is selected automatically.
21-
plt::plot(x, y);
22-
// Plot a line whose name will show up as "log(x)" in the legend.
23-
plt::named_plot("log(x)", x, z);
16+
if (i % 10 == 0) {
17+
// Clear previous plot
18+
plt::clf();
19+
// Plot line from given x and y data. Color is selected automatically.
20+
plt::plot(x, y);
21+
// Plot a line whose name will show up as "log(x)" in the legend.
22+
plt::plot(x, z, {{"label", "log(x)"}});
2423

25-
// Set x-axis to interval [0,1000000]
26-
plt::xlim(0, n*n);
24+
// Set x-axis to interval [0,1000000]
25+
plt::xlim(0, n * n);
2726

28-
// Add graph title
29-
plt::title("Sample figure");
30-
// Enable legend.
31-
plt::legend();
32-
// Display plot continuously
33-
plt::pause(0.01);
34-
}
35-
}
27+
// Add graph title
28+
plt::title("Sample figure");
29+
// Enable legend.
30+
plt::legend();
31+
// Display plot continuously
32+
plt::pause(0.01);
33+
}
34+
}
3635
}

examples/basic.cpp

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,44 @@
11
#define _USE_MATH_DEFINES
2-
#include <iostream>
3-
#include <cmath>
42
#include "../matplotlibcpp.h"
3+
#include <cmath>
4+
#include <iostream>
55

66
namespace plt = matplotlibcpp;
77

8-
int main()
9-
{
10-
// Prepare data.
11-
int n = 5000;
12-
std::vector<double> x(n), y(n), z(n), w(n,2);
13-
for(int i=0; i<n; ++i) {
14-
x.at(i) = i*i;
15-
y.at(i) = sin(2*M_PI*i/360.0);
16-
z.at(i) = log(i);
17-
}
18-
19-
// Set the size of output image = 1200x780 pixels
20-
plt::figure_size(1200, 780);
21-
22-
// Plot line from given x and y data. Color is selected automatically.
23-
plt::plot(x, y);
24-
25-
// Plot a red dashed line from given x and y data.
26-
plt::plot(x, w,"r--");
27-
28-
// Plot a line whose name will show up as "log(x)" in the legend.
29-
plt::named_plot("log(x)", x, z);
30-
31-
// Set x-axis to interval [0,1000000]
32-
plt::xlim(0, 1000*1000);
33-
34-
// Add graph title
35-
plt::title("Sample figure");
36-
37-
// Enable legend.
38-
plt::legend();
39-
40-
// save figure
41-
const char* filename = "./basic.png";
42-
std::cout << "Saving result to " << filename << std::endl;;
43-
plt::save(filename);
8+
int main() {
9+
// Prepare data.
10+
int n = 5000;
11+
std::vector<double> x(n), y(n), z(n), w(n, 2);
12+
for (int i = 0; i < n; ++i) {
13+
x.at(i) = i * i;
14+
y.at(i) = sin(2 * M_PI * i / 360.0);
15+
z.at(i) = log(i);
16+
}
17+
18+
// Set the size of output image = 1200x780 pixels
19+
plt::figure_size(1200, 780);
20+
21+
// Plot line from given x and y data. Color is selected automatically.
22+
plt::plot(x, y);
23+
24+
// Plot a red dashed line from given x and y data.
25+
plt::plot(x, w, "r--");
26+
27+
// Plot a line whose name will show up as "log(x)" in the legend.
28+
plt::plot(x, z, {{"label", "log(x)"}});
29+
30+
// Set x-axis to interval [0,1000000]
31+
plt::xlim(0, 1000 * 1000);
32+
33+
// Add graph title
34+
plt::title("Sample figure");
35+
36+
// Enable legend.
37+
plt::legend();
38+
39+
// save figure
40+
const char *filename = "./basic.png";
41+
std::cout << "Saving result to " << filename << std::endl;
42+
;
43+
plt::save(filename);
4444
}

examples/nonblock.cpp

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,44 @@
11
#define _USE_MATH_DEFINES
2-
#include <cmath>
32
#include "../matplotlibcpp.h"
3+
#include <cmath>
44

55
namespace plt = matplotlibcpp;
66

7-
87
using namespace matplotlibcpp;
98
using namespace std;
109

11-
int main()
12-
{
13-
// Prepare data.
14-
int n = 5000;
15-
std::vector<double> x(n), y(n), z(n), w(n,2);
16-
for(int i=0; i<n; ++i) {
17-
x.at(i) = i*i;
18-
y.at(i) = sin(2*M_PI*i/360.0);
19-
z.at(i) = log(i);
20-
}
21-
22-
// Plot line from given x and y data. Color is selected automatically.
23-
plt::subplot(2,2,1);
24-
plt::plot(x, y);
25-
26-
// Plot a red dashed line from given x and y data.
27-
plt::subplot(2,2,2);
28-
plt::plot(x, w,"r--");
29-
30-
// Plot a line whose name will show up as "log(x)" in the legend.
31-
plt::subplot(2,2,3);
32-
plt::named_plot("log(x)", x, z);
33-
34-
// Set x-axis to interval [0,1000000]
35-
plt::xlim(0, 1000*1000);
36-
37-
// Add graph title
38-
plt::title("Sample figure");
39-
// Enable legend.
40-
plt::legend();
41-
42-
plt::show(false);
43-
44-
cout << "matplotlibcpp::show() is working in an non-blocking mode" << endl;
45-
getchar();
10+
int main() {
11+
// Prepare data.
12+
int n = 5000;
13+
std::vector<double> x(n), y(n), z(n), w(n, 2);
14+
for (int i = 0; i < n; ++i) {
15+
x.at(i) = i * i;
16+
y.at(i) = sin(2 * M_PI * i / 360.0);
17+
z.at(i) = log(i);
18+
}
19+
20+
// Plot line from given x and y data. Color is selected automatically.
21+
plt::subplot(2, 2, 1);
22+
plt::plot(x, y);
23+
24+
// Plot a red dashed line from given x and y data.
25+
plt::subplot(2, 2, 2);
26+
plt::plot(x, w, "r--");
27+
28+
// Plot a line whose name will show up as "log(x)" in the legend.
29+
plt::subplot(2, 2, 3);
30+
plt::plot(x, z, {{"label", "log(x)"}});
31+
32+
// Set x-axis to interval [0,1000000]
33+
plt::xlim(0, 1000 * 1000);
34+
35+
// Add graph title
36+
plt::title("Sample figure");
37+
// Enable legend.
38+
plt::legend();
39+
40+
plt::show(false);
41+
42+
cout << "matplotlibcpp::show() is working in an non-blocking mode" << endl;
43+
getchar();
4644
}

examples/update.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ int main() {
3636
plt::axis("equal");
3737

3838
// Plot sin once and for all.
39-
plt::named_plot("sin", x, y);
39+
plt::plot(x, y, {{"label", "sin"}});
4040

4141
// Prepare plotting the tangent.
4242
plt::Plot plot("tangent");

matplotlibcpp.h

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,59 +1039,6 @@ bool errorbar(const std::vector<NumericX> &x, const std::vector<NumericY> &y,
10391039
return res;
10401040
}
10411041

1042-
template <typename Numeric>
1043-
bool named_plot(const std::string &name, const std::vector<Numeric> &y,
1044-
const std::string &format = "") {
1045-
PyObject *kwargs = PyDict_New();
1046-
PyDict_SetItemString(kwargs, "label", PyString_FromString(name.c_str()));
1047-
1048-
PyObject *yarray = get_array(y);
1049-
1050-
PyObject *pystring = PyString_FromString(format.c_str());
1051-
1052-
PyObject *plot_args = PyTuple_New(2);
1053-
1054-
PyTuple_SetItem(plot_args, 0, yarray);
1055-
PyTuple_SetItem(plot_args, 1, pystring);
1056-
1057-
PyObject *res = PyObject_Call(
1058-
detail::_interpreter::get().s_python_function_plot, plot_args, kwargs);
1059-
1060-
Py_DECREF(kwargs);
1061-
Py_DECREF(plot_args);
1062-
if (res)
1063-
Py_DECREF(res);
1064-
1065-
return res;
1066-
}
1067-
1068-
template <typename Numeric>
1069-
bool named_plot(const std::string &name, const std::vector<Numeric> &x,
1070-
const std::vector<Numeric> &y, const std::string &format = "") {
1071-
PyObject *kwargs = PyDict_New();
1072-
PyDict_SetItemString(kwargs, "label", PyString_FromString(name.c_str()));
1073-
1074-
PyObject *xarray = get_array(x);
1075-
PyObject *yarray = get_array(y);
1076-
1077-
PyObject *pystring = PyString_FromString(format.c_str());
1078-
1079-
PyObject *plot_args = PyTuple_New(3);
1080-
PyTuple_SetItem(plot_args, 0, xarray);
1081-
PyTuple_SetItem(plot_args, 1, yarray);
1082-
PyTuple_SetItem(plot_args, 2, pystring);
1083-
1084-
PyObject *res = PyObject_Call(
1085-
detail::_interpreter::get().s_python_function_plot, plot_args, kwargs);
1086-
1087-
Py_DECREF(kwargs);
1088-
Py_DECREF(plot_args);
1089-
if (res)
1090-
Py_DECREF(res);
1091-
1092-
return res;
1093-
}
1094-
10951042
template <typename Numeric>
10961043
bool named_semilogx(const std::string &name, const std::vector<Numeric> &x,
10971044
const std::vector<Numeric> &y,

0 commit comments

Comments
 (0)
0