In the code below, five examples (replace input0(); with input1(); ... input4(); in main() to load the data for the other examples) demonstrate issues I had with the filed contour plots contourf. I presume that those issues might be related (or maybe they are not). Apart from that, I'd like to thank you for this excellent library - I was stunned when I stumbled upon the project :) Not having to export examples to a Matlab code to merely check them out there is tremendous help.
Example 0 (input0):
Produces a segfault when the figure is generated with figure(true);.
GDB says (see also backtrace below) this happens in matplot::contours::is_lower_level
In the reactive mode (figure(false);), segfault is not produced; however, the calculated levels, as indicated by the colorbar, are garbage. See the produced plot below.
For comparison: the other image for this example is produced by Matlab's contourf version on the same data.
It should be noted that X, Y in this example are not produced by meshgrid (rather, they correspond to $r\cos(\phi)$ and $r\sin(\phi)$, where the data for $r$ and $\phi$ are generated by meshgrid). I could not produce an example where the segfault happened with data of the from auto [X, Y] = meshgrid(x, y);
Images for example 0
![img0F](https://user-images.githubusercontent.com/56190101/212282066-78705d1d-984b-4aa4-85bb-ac28808b2b4c.png)
![img0M](https://user-images.githubusercontent.com/56190101/212282106-8c715981-8c64-478e-9c6c-48153b12e2b1.png)
Example 1 (input1):
The data are consistent with the output of meshgrid;
Now, no segfault, but the levels are still infinite and the produced plot nonsensical (specifically, filling is all wrong; the contours themselves, plotted with solid lines, actually appear OK). See the first plot below.
It should be noted that now both reactive and quiet mode produce the same figure.
For comparison, the other figure is generated by Matlab from the same data.
Images for example 1
![img1](https://user-images.githubusercontent.com/56190101/212285887-89ee470b-217f-4644-a205-a3bcbbbd9fc8.png)
![img1M](https://user-images.githubusercontent.com/56190101/212285908-8b0696eb-bba7-43ec-bebe-603cdf72a751.png)
Example 2 (input2):
The data are consistent with the output of meshgrid;
The calculated levels (as indicated by the colorbar) are now finite (and appear correct). However, the plot is filled improperly, with shaded regions not corresponding to the actual level lines.
The first image below produced by matplot++, the second by Matlab on the same data.
Images for example 2
![img2](https://user-images.githubusercontent.com/56190101/212287326-b753ca34-f27a-4cf8-8661-7b7e44be13a3.png)
![img2M](https://user-images.githubusercontent.com/56190101/212287345-6ff51137-1f48-4bc3-826c-99fc7a67a443.png)
Example 3 (input3):
The data are not consistent with the output of meshgrid, but of the form $r\cos(\phi)$ and $r\sin(\phi)$, similarly as in Example 0. For this simple function, the plot is produced (and the levels are finite), but...
The rows in X, Y, Z correspond to values of $\phi$, with the first and last being $0$ and $2\pi$, respectively (similarly as in Example 0). However, matplot++ produces an example with a sector 'cut out', see the first image below. Matlab on the same data produces a correct contour plot.
The generated data in this example (and also Example 0) contain also two identical (up to numerical accuracy) rows corresponding to $\phi=\pi$ (as well as for $\phi \in {0,2\pi}$, of course); I did play around with the examples either by removing the identical rows (or making them truly identical, instead of up to $10^{-15}$ precision), but it did not help (also, the segfault in Example 0 was generated in all these variants).
Images for example 3
![img3](https://user-images.githubusercontent.com/56190101/212289362-492b0162-430d-4e7e-a9ef-f37e4e753687.png)
![img3M](https://user-images.githubusercontent.com/56190101/212289432-43b7e7e9-7f7e-4d18-a625-5a93e99ad634.png)
Example 4 (input4):
This is to be contrasted with Example 3: the cutout issue is solved by adding an additional row, duplicate of the first nonzero value of $\phi$ (i.e., we essentially do X.push_back(X[1]); for all arrays in Example 3).
Now matplot++ produces a correct plot (see below); also so does Matlab on the same data (and the resulting plot is identical to img3M above).
In Example 0, such an addition of extra rows does not help with the segfault, however.
Image for example 4
![img4](https://user-images.githubusercontent.com/56190101/212289951-738887b5-6dd8-4d6d-b1cc-48c14e7a0130.png)
Additional notes
In Examples 1-4, both figure(false); and figure(true); reproduce the same behavior, i.e., the improper filling does not depend upon the mode for figure.
If one uncomments //contourf(X,Y,Z); but comments out the three lines above, the behavior is the same in all examples.
I did notice there have been some issues with contourf and even the matplot::contours::is_lower_level member (e.g., the open issue #77 - but not sure if it is related)
For reporting purposes, the matplot++ library was built with CMAKE_BUILD_TYPE=Debug (but the bug was present also on the Release version):
GNU gdb (Ubuntu 12.1-3ubuntu2) 12.1 output
```bash
gdb out
```
```
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[Detaching after vfork from child process 11148]
[Detaching after vfork from child process 11150]
[Detaching after vfork from child process 11151]
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff75b33d1 in matplot::contours::is_lower_level(unsigned long, unsigned long, unsigned long) () from /usr/local/lib/libmatplot.so
(gdb) backtrace
#0 0x00007ffff75b33d1 in matplot::contours::is_lower_level(unsigned long, unsigned long, unsigned long) () from /usr/local/lib/libmatplot.so
#1 0x00007ffff75bee45 in matplot::contours::plot_string[abi:cxx11]() () from /usr/local/lib/libmatplot.so
#2 0x00007ffff74ade2f in matplot::axes_type::run_plot_objects_command() () from /usr/local/lib/libmatplot.so
#3 0x00007ffff74e4c59 in matplot::figure_type::send_gnuplot_draw_commands() () from /usr/local/lib/libmatplot.so
#4 0x00007ffff74e5315 in matplot::figure_type::draw() () from /usr/local/lib/libmatplot.so
#5 0x0000555555557b18 in main () at prog.cpp:14
(gdb)
```
Bug category
Describe the bug
In the code below, five examples (replace
input0();
withinput1();
...input4();
inmain()
to load the data for the other examples) demonstrate issues I had with the filed contour plotscontourf
. I presume that those issues might be related (or maybe they are not). Apart from that, I'd like to thank you for this excellent library - I was stunned when I stumbled upon the project :) Not having to export examples to a Matlab code to merely check them out there is tremendous help.Example 0 (
input0
):figure(true);
.matplot::contours::is_lower_level
figure(false);
), segfault is not produced; however, the calculated levels, as indicated by the colorbar, are garbage. See the produced plot below.contourf
version on the same data.X
,Y
in this example are not produced bymeshgrid
(rather, they correspond to $r\cos(\phi)$ and $r\sin(\phi)$, where the data for $r$ and $\phi$ are generated bymeshgrid
). I could not produce an example where the segfault happened with data of the fromauto [X, Y] = meshgrid(x, y);
Images for example 0
![img0F](https://user-images.githubusercontent.com/56190101/212282066-78705d1d-984b-4aa4-85bb-ac28808b2b4c.png) ![img0M](https://user-images.githubusercontent.com/56190101/212282106-8c715981-8c64-478e-9c6c-48153b12e2b1.png)Example 1 (
input1
):meshgrid
;Images for example 1
![img1](https://user-images.githubusercontent.com/56190101/212285887-89ee470b-217f-4644-a205-a3bcbbbd9fc8.png) ![img1M](https://user-images.githubusercontent.com/56190101/212285908-8b0696eb-bba7-43ec-bebe-603cdf72a751.png)Example 2 (
input2
):meshgrid
;matplot++
, the second by Matlab on the same data.Images for example 2
![img2](https://user-images.githubusercontent.com/56190101/212287326-b753ca34-f27a-4cf8-8661-7b7e44be13a3.png) ![img2M](https://user-images.githubusercontent.com/56190101/212287345-6ff51137-1f48-4bc3-826c-99fc7a67a443.png)Example 3 (
input3
):meshgrid
, but of the form $r\cos(\phi)$ and $r\sin(\phi)$, similarly as in Example 0. For this simple function, the plot is produced (and the levels are finite), but...X
,Y
,Z
correspond to values of $\phi$, with the first and last being $0$ and $2\pi$, respectively (similarly as in Example 0). However,matplot++
produces an example with a sector 'cut out', see the first image below. Matlab on the same data produces a correct contour plot.Images for example 3
![img3](https://user-images.githubusercontent.com/56190101/212289362-492b0162-430d-4e7e-a9ef-f37e4e753687.png) ![img3M](https://user-images.githubusercontent.com/56190101/212289432-43b7e7e9-7f7e-4d18-a625-5a93e99ad634.png)Example 4 (
input4
):X.push_back(X[1]);
for all arrays in Example 3).matplot++
produces a correct plot (see below); also so does Matlab on the same data (and the resulting plot is identical toimg3M
above).Image for example 4
![img4](https://user-images.githubusercontent.com/56190101/212289951-738887b5-6dd8-4d6d-b1cc-48c14e7a0130.png)Additional notes
figure(false);
andfigure(true);
reproduce the same behavior, i.e., the improper filling does not depend upon the mode for figure.//contourf(X,Y,Z);
but comments out the three lines above, the behavior is the same in all examples.contourf
and even thematplot::contours::is_lower_level
member (e.g., the open issue #77 - but not sure if it is related)matplot++
library was built withCMAKE_BUILD_TYPE=Debug
(but the bug was present also on the Release version):contour(X,Y,Z)
in all examples and settings worked perfectly.Steps to Reproduce
Source code and data:
```cpp #includeBuilding:
Output
GNU gdb (Ubuntu 12.1-3ubuntu2) 12.1 output
```bash gdb out ``` ``` [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". [Detaching after vfork from child process 11148] [Detaching after vfork from child process 11150] [Detaching after vfork from child process 11151] Program received signal SIGSEGV, Segmentation fault. 0x00007ffff75b33d1 in matplot::contours::is_lower_level(unsigned long, unsigned long, unsigned long) () from /usr/local/lib/libmatplot.so (gdb) backtrace #0 0x00007ffff75b33d1 in matplot::contours::is_lower_level(unsigned long, unsigned long, unsigned long) () from /usr/local/lib/libmatplot.so #1 0x00007ffff75bee45 in matplot::contours::plot_string[abi:cxx11]() () from /usr/local/lib/libmatplot.so #2 0x00007ffff74ade2f in matplot::axes_type::run_plot_objects_command() () from /usr/local/lib/libmatplot.so #3 0x00007ffff74e4c59 in matplot::figure_type::send_gnuplot_draw_commands() () from /usr/local/lib/libmatplot.so #4 0x00007ffff74e5315 in matplot::figure_type::draw() () from /usr/local/lib/libmatplot.so #5 0x0000555555557b18 in main () at prog.cpp:14 (gdb) ```valgrind output (if that's of any help):
Output: https://pastebin.com/TeQxuWv0
Platform
Environment Details: