alandefreitas/matplotplusplus

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

aminya opened this issue · 2 comments

Bug category

  • bug - compilation error
  • bug - compilation warning
  • bug - runtime error
  • bug - runtime warning
  • bug - logic error

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

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

  • cross-platform issue - linux
  • cross-platform issue - windows
  • cross-platform issue - macos

Environment Details:

  • OS: Kubuntu
  • OS Version: 22.04
  • Compiler: Clang
  • Compiler version: 15

Additional context

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.

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.