Lightness Races in Orbit
Lightness Races in Orbit

Reputation: 385106

Can I set a default Y range in gnuplot?

My graphs will be generated based on runtime data, such as user-provided time ranges. I can't know ahead of time whether data within the requested xrange will actually exist.

In the case that it's not, I'd like to show a blank plot (with X=time range as requested, but arbitrary Y scale) rather than having to handle an error message "all points y value undefined!".

I've read that it's possible to run stats (in gnuplot 4.6) or its gnuplot 4.4 equivalent of running plot with set term unknown to collect stats, then manually set up a range before plotting properly.

However, I'm concerned about effectively running plot twice over a ~200MB ASCII input, and it seems wasteful to scan the entire file like that just to determine an Y range when I don't actually need any particular Y range in the case that my set xrange directive doesn't encompass any datapoints.

Is it possible to persuade gnuplot to just quietly accept a lack of datapoints and show me an empty graph, without iterating over the data any more than I already do?

Upvotes: 3

Views: 723

Answers (1)

Christoph
Christoph

Reputation: 48390

The error message arises from the autoscaling. Only if you set a fixed yrange you can plot an empty graph. As example consider

plot 1/0

which gives the same error message all points y value undefined!, whereas the commands

plot [][0:1] 1/0

generates an empty graph.

And no, gnuplot doesn't have any sort of default yrange which is used when autoscaling fails (also not in version 5.0). I guess it is not gnuplot's workspace, to automatically handle wrong user input and display an empty graph no matter what invalid input it got.

Upvotes: 2

Related Questions