File tree Expand file tree Collapse file tree 4 files changed +27
-3
lines changed Expand file tree Collapse file tree 4 files changed +27
-3
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,8 @@ int main()
41
41
z.at(i) = log(i);
42
42
}
43
43
44
+ // Set the size of output image = 1200x780 pixels
45
+ plt::figure_size(1200, 780);
44
46
// Plot line from given x and y data. Color is selected automatically.
45
47
plt::plot(x, y);
46
48
// Plot a red dashed line from given x and y data.
Original file line number Diff line number Diff line change @@ -15,9 +15,11 @@ int main()
15
15
y.at (i) = sin (2 *M_PI*i/360.0 );
16
16
z.at (i) = log (i);
17
17
}
18
-
19
- // Plot line from given x and y data. Color is selected automatically.
20
- plt::plot (x, y);
18
+
19
+ // Set the size of output image = 1200x780 pixels
20
+ plt::figure_size (1200 , 780 );
21
+ // Plot line from given x and y data. Color is selected automatically.
22
+ plt::plot (x, y);
21
23
// Plot a red dashed line from given x and y data.
22
24
plt::plot (x, w," r--" );
23
25
// Plot a line whose name will show up as "log(x)" in the legend.
Original file line number Diff line number Diff line change @@ -751,6 +751,26 @@ inline void figure()
751
751
Py_DECREF (res);
752
752
}
753
753
754
+ inline void figure_size (size_t w, size_t h)
755
+ {
756
+ const size_t dpi = 100 ;
757
+ PyObject* size = PyTuple_New (2 );
758
+ PyTuple_SetItem (size, 0 , PyFloat_FromDouble ((double )w / dpi));
759
+ PyTuple_SetItem (size, 1 , PyFloat_FromDouble ((double )h / dpi));
760
+
761
+ PyObject* kwargs = PyDict_New ();
762
+ PyDict_SetItemString (kwargs, " figsize" , size);
763
+ PyDict_SetItemString (kwargs, " dpi" , PyLong_FromSize_t (dpi));
764
+
765
+ PyObject* res = PyObject_Call (detail::_interpreter::get ().s_python_function_figure ,
766
+ detail::_interpreter::get ().s_python_empty_tuple , kwargs);
767
+
768
+ Py_DECREF (kwargs);
769
+
770
+ if (!res) throw std::runtime_error (" Call to figure_size() failed." );
771
+ Py_DECREF (res);
772
+ }
773
+
754
774
inline void legend ()
755
775
{
756
776
PyObject* res = PyObject_CallObject (detail::_interpreter::get ().s_python_function_legend , detail::_interpreter::get ().s_python_empty_tuple );
You can’t perform that action at this time.
0 commit comments