alandefreitas / matplotplusplus

Matplot++: A C++ Graphics Library for Data Visualization 📊🗾
https://alandefreitas.github.io/matplotplusplus/
MIT License
4.1k stars 311 forks source link

Warning: empty y range [0:0], adjusting to [-1:1] #338

Open aminya opened 1 year ago

aminya commented 1 year ago

Bug category

Describe the bug

When building subplots with the gnuplot backend, even though the ylim is set, I still get this warning during the plot:

Warning: empty y range [0:0], adjusting to [-1:1]
Warning: empty y range [0:0], adjusting to [-1:1]
Warning: empty y range [0:0], adjusting to [-1:1]
Warning: empty y range [0:0], adjusting to [-1:1]
Warning: empty y range [0:0], adjusting to [-1:1]
Warning: empty y range [0:0], adjusting to [-1:1]
Warning: empty y range [0:0], adjusting to [-1:1]
Warning: empty y range [0:0], adjusting to [-1:1]

Steps to Reproduce

Try using figure axes and and add_subplot

auto fig_ax = fig->add_subplot(..., ...);
fig_ax->ylim({-1,1});
fig_ax->plot(...,...);

Output

```console Warning: empty y range [0:0], adjusting to [-1:1] Warning: empty y range [0:0], adjusting to [-1:1] Warning: empty y range [0:0], adjusting to [-1:1] Warning: empty y range [0:0], adjusting to [-1:1] Warning: empty y range [0:0], adjusting to [-1:1] Warning: empty y range [0:0], adjusting to [-1:1] Warning: empty y range [0:0], adjusting to [-1:1] Warning: empty y range [0:0], adjusting to [-1:1] ```

Platform

Environment Details:

Additional context

Keith-Dao commented 1 year ago

I just ran into this warning recently as well. The following removed the runtime warnings for me:

auto fig_ax = fig->add_subplot(..., ...);
matplot::yrange(fig_ax, {-1,1});
fig_ax->plot(...,...);

Hope this helps.

alandefreitas commented 1 year ago

Yes. Because of how pipes work there's no two-way communication between gnuplot and matplot. The only solution is to preemptively adjust the ranges to avoid the warnings. matplot could attempt to do that automatically internally, but the logic might become quite complex is some cases.