Create Stick Plot w/ IDL Code: Title Under 65 Chars

In summary: As for a better way of doing it, you could experiment with different symbols or line styles to see if they better suit your needs. Overall, your procedure seems to work well and produces clear and concise stick plots.
  • #1
cepheid
Staff Emeritus
Science Advisor
Gold Member
5,199
38
Today I was trying to figure out how to create a stick plot using IDL. I'm talking about a plot in which each data point is connected to the x-axis by a vertical line. It is often used to visualize time sequences and other discrete data in engineering. I've also heard it called a stem plot, but a Google search for that revealed mostly stem and leaf plots (which are something different entirely). I know that it is possible to create a stick plot in MATLAB, but I could not find any IDL procedure to do so. I decided to write my own procedure, thinking that it would be simple. Examples of the output from my code are attached below, along with the code itself.

For those who know IDL but don't want to read the entire code, what I did was basically use the PLOT command to plot the data points, and then use the PLOTS command to draw a vertical line connected to each one (with a FOR loop, unfortunately).

I'm wondering:

1. Is the an existing IDL procedure to do this (which would be embarrassing)?
2. If not, is there a better way of doing it than what I have come up with?

http://img30.imageshack.us/img30/6823/gaussian.png
http://img30.imageshack.us/img30/1515/logxzb.png
http://img26.imageshack.us/img26/1610/sine.png
Code:
; NAME:           STICKPLOT

; PURPOSE:        This procedure creates IDL plots of data in which
;                 each data point is connected to the x-axis by a
;                 vertical stick. This type of plot is often used in
;                 the context of engineering to visualize time
;                 sequences or other discrete data. It is entirely
;                 possible that a procedure to do this already exists
;                 in IDL, making this a wasted endeavour.

; AUTHOR:         XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

; LAST REVISED:   June 11, 2009

; The Call to the Procedure:

; STICKPLOT, x, y [, xrange = [minvalue, maxvalue]] [, yrange =
; [minvalue, max value] [, psym=value] [, xtitle = 'string'] [,
; ytitle='string'] [, title = 'string']
PRO STICKPLOT, x, y, xrange = xr, yrange = yr, psym = psym,$
  xtitle = xtitle, ytitle = ytitle, title = title

; Create a custom symbol for marking data points (a filled circle)

  A = findgen(17)*(!PI*2/16)

  USERSYM, cos(A),sin(A),/fill

; If the user does not specify a symbol for the data points, default
; to the filled circles:

  if ~keyword_set(psym) then psym = 8
  
; If the user does not specify a range for the x values, set it to the
; full range of x values:

  if ~keyword_set(xr) then xr = [min(x), max(x)]

; If the user does not specify a range for the y values, set the
; lower limit to the smallest in the array, OR zero (whichever is
; less), and set the upper limit to the largest y value in the array

  if ~keyword_set(yr) then yr = [0<min(y), max(y)]

; Plot the data points:

  plot, x, y, xr = xr, yr = yr,  /xs, /ys, psym=psym, xtitle = xtitle,$
  ytitle = ytitle, title = title
  
; Create a "clipped" version of the y array so that the vertical lines
; that are to be drawn will not exceed the limits of the plot's y range

  lim = y < yr[1] > (yr[0])

; Find out the y limit that is smallest (in absolute value) so that
; the sticks can start from here (if required)

  absyr = abs(yr)

  sorted = sort(absyr)

; If there is a sign change in the y plot limits, then start all of
; the sticks at zero. Otherwise, start the sticks at the top or the
; bottom of the plot (as the case may be). In either case, use a for
; loop to draw n sticks, one for each value:

  if (yr[0]*yr[1] gt 0) then for i = min(where(x ge xr[0])),$
  max(where(x le xr[1])) do plots, [x[i],x[i]], [yr[sorted[0]],lim[i]]$
  else for i = min(where(x ge xr[0])),max(where(x le xr[1])) do plots,$
  [x[i],x[i]], [0,lim[i]]

END
 
Last edited by a moderator:
Physics news on Phys.org
  • #2
To answer your questions, it does not appear that there is an existing IDL procedure to create a stick plot. However, you have come up with an effective solution using the PLOT and PLOTS commands. You could try searching for other solutions or asking other IDL users on forums or discussion boards if they know of any existing procedures.
 

1. What is a stick plot?

A stick plot is a type of graph used to display data points along a horizontal time axis. It is often used to show changes in a variable over time.

2. How do I create a stick plot with IDL code?

To create a stick plot with IDL code, you first need to import your data and then use the PLOT command. You can specify the type of plot (in this case, stick) and add a title using the TITLE command.

3. What is the maximum length for the title in a stick plot?

The maximum length for the title in a stick plot is 65 characters. This is to ensure that the title does not take up too much space and remains easily readable.

4. Can I customize the appearance of my stick plot with IDL code?

Yes, you can customize the appearance of your stick plot by using various options in the PLOT command, such as changing the color, size, and style of the sticks. You can also add labels, legends, and other visual elements to enhance the plot.

5. Is IDL the only programming language that can create stick plots?

No, there are many other programming languages that can create stick plots, such as Python, R, and Matlab. It ultimately depends on your personal preference and the specific features and capabilities of each language.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
925
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
2K
  • Programming and Computer Science
Replies
6
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
7K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • Programming and Computer Science
Replies
1
Views
5K
Back
Top