How do I plot step functions in gnuplot?

Click For Summary

Discussion Overview

The discussion focuses on how to plot step functions in gnuplot, particularly the floor and greatest integer functions. Participants explore various methods to achieve the desired visual representation of these functions from the command line, including adjustments to sampling resolution and the use of piecewise-defined functions.

Discussion Character

  • Technical explanation
  • Exploratory
  • Mathematical reasoning

Main Points Raised

  • One participant expresses confusion regarding a demo on the gnuplot website and requests guidance on plotting step functions, specifically the floor function.
  • Another participant provides examples of plotting the floor and ceil functions but notes that these examples seem to require external data files.
  • A later reply mentions that while plotting the functions results in horizontal lines, slanted lines appear connecting these horizontal segments, prompting a request for a solution to eliminate them.
  • One suggestion is made to increase the sampling resolution using the command "set samples 10000" to improve the appearance of the plot.
  • Another participant shares a method involving piecewise-defined functions to create step functions, suggesting the use of illegal parts to achieve the desired output.
  • A further suggestion is made to declare a step function using the signum function with a specific command.

Areas of Agreement / Disagreement

Participants present multiple approaches and suggestions, indicating that there is no consensus on a single method for plotting step functions in gnuplot. The discussion remains unresolved as participants explore different techniques.

Contextual Notes

Some limitations include the dependence on sampling resolution and the potential need for external data files, which may affect the plotting of step functions. The effectiveness of different methods has not been fully established.

neutrino
Messages
2,093
Reaction score
2
Among the demos at the gnuplot website, I saw this - http://gnuplot.sourceforge.net/demo/steps.1.gnu, but it does not make much sense to me. :(

Could someone tell me how to plot step functions from the command line, just like you would the usual functions? Specifically, I'd like to plot floor/greatest integer functions.

Thanks
 
Physics news on Phys.org
plot [-5:5][-5:5] floor(3*sin(x))

plot [-5:5][-5:5] ceil(x**2)

Your examples seem to require external data files.
 
robphy said:
plot [-5:5][-5:5] floor(3*sin(x))

plot [-5:5][-5:5] ceil(x**2)

Your examples seem to require external data files.

Thanks a lot, robphy! :-)

EDIT: I just tried an example. While it does plot the lines of constancy, there are slanted lines that "connect" the horizontal ones. Is there a way I could get rid of them, i.e., the slanted ones?
 
Last edited:
Try to increasing the sampling resolution before plotting:

set samples 10000
 
robphy said:
Try to increasing the sampling resolution before plotting:

set samples 10000

Nice. Although the slants have only become vertical, they at least look like steps. :biggrin: Thanks, again. :)
 
http://www6.uniovi.es/gptug/node5.html
makes a suggestion to plot two piecewise-defined functions with illegal parts:

f1(x)=(x<1) ? 0 : sqrt(-1)
f2(x)=(x<1) ? sqrt(-1): 1

plot [-5:5][-2:2] f1(x),f2(x)

you'll have to poke around to set the color of each function to be the same
 
You can declare a step function by using signum function by entering the command:

u(x,t)=(1+sgn(x-t))/2
 

Similar threads

Replies
5
Views
13K
  • · Replies 12 ·
Replies
12
Views
7K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 4 ·
Replies
4
Views
6K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 9 ·
Replies
9
Views
5K
  • · Replies 3 ·
Replies
3
Views
2K