[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Ploting a Temperature field

From: John Smith
Subject: Re: Ploting a Temperature field
Date: Wed, 15 Mar 2000 19:57:52 +0000 (GMT)

On Wed, 15 Mar 2000, Rober Frobeen wrote:

> As the result of my calculations I got a matrix with the Temperature
> values of a x-y mesh in it.
> For a first overview I would like to plot them as an Temperature field
> in a x-y plane where each temperature got a x and a y value and the
> temperature value is displayed as a colour.

> To plot this, there is the command "pcolor" in matlab. Is there a
> similar command in octave? If so, which one is it and how is it applied? 

Raw Octave is not too useful here, but there are some approaches. 
Does anyone else have favourite ways to do this sort of thing?

A very crude method might be based on this sort of logic:

## calculate the temperature...
  nx = 200 ;
  ny = 150 ;
  x = ones(ny,1) * linspace(-10,10,nx) ;
  y = linspace(-10,10,ny)' * ones(1,nx);

  temp= sin(x.*x + y.*y) ./ (x.*x + y.*y) ;

## Display it...
  colormap(ocean) ;
  imagesc(temp) ;

A better approach might be to use a little (may be well) known 
tool called plotmtv; I seem to have been using plotmtv 1.4.1. 
A semi-general function (posted here some time ago) is attached below.
You might call it like this:

## Calculate temperature
      n = 40 ;
      x = linspace( -10,10,n ) ;
      y = linspace( -10,10,n ) ;
      xx = ones(n,1) * x ;
      yy = y' * ones(1,n) ;
      rr = sqrt(xx.*xx + yy.*yy ) + 1e-6 ;
      temp = sin(rr) ./ rr ;  
## Display it
      mtv_ctr( x, y, temp ) ;

Then click on the "3D Plot" button in the top left corner to get
a 2D map.

There is a useful manual that comes with plotmtv that explains how 
to write the input files, to add titles and all things pretty.

Hope this helps,

  John Smith

function mtv_ctr (t, u, v, w)
# usage: mtv_ctr(Z), mtv_ctr(Z,V), mtv_ctr(x,y,Z)  or  mtv_ctr(x,y,Z,V)
# where Z is a n x m matrix of values of f(x,y), x along rows & y UP cols
# i.e. it is assumed that Z has been obtained by the equivalent of
# [X,Y]=meshdom(x,y); Z = f(X,Y);
# and V is either an integer number of contours (default = 10)
#          or a vector of contour-level values (max = 98)
# The dimensions of the Z-mesh should both be not greater than 99.
# This uses the Plotmtv CONTOUR data format (Data Format Manual Sect. 7)
# Additional Plotmtv command-line options can be set in the
#        octave string variable mtv_options. (Not implemented)
# See also: plot, semilogx, semilogy, loglog, polar, meshdom, contour,
#           bar, stairs, gplot, gsplot, replot, xlabel, ylabel, title 

# Created by Ted Harding June 1996
# Possibly changed by John Smith 1999-2000.

# This file is part of Octave.

  if (nargin == 1), z=t; x=y=[]; V=10; endif
  if (nargin == 2), z=t; V=u; x=y=[]; endif
  if (nargin == 3), x=t; y=u; z=v; V=10; endif
  if (nargin == 4), x=t; y=u; z=v; V=w; endif

  if (is_matrix (z))
    m = columns(z); n = rows(z);
    error ("mesh: argument must be a matrix");

  if (is_vector(x) && is_vector(y))
    if (columns(x)==1), x=x'; endif
    if (columns(y)==1), y=y'; endif
    x = (1:m); y = (1:n);

  z = flipud(z);

  file = "/tmp/mtv_curves_dat";
  FILENUM = fopen(file,"a");
  fprintf(FILENUM,"\n\n$ data=CONTOUR\n\n");
%% For non-rectangular-grid data (e.g. polar) try e.g.
%% printf(FILENUM,"\n\n$ data=CONTCURVE\n\n");
%% instead of the above line.
  fprintf(FILENUM,"%% xlabel=\"\"\n");
  fprintf(FILENUM,"%% ylabel=\"\"\n");
  fprintf(FILENUM,"%% zlabel=\"\"\n");
  fprintf(FILENUM,"%% toplabel=\"\"\n");
  fprintf(FILENUM,"%% subtitle=\"\"\n");
  fprintf(FILENUM,"%% contstyle=2\n\n");

  fprintf(FILENUM,"%% hiddenline=True\n");
  fprintf(FILENUM,"%% eyepos.y=%g\n",-sqrt(3));
  fprintf(FILENUM,"%% eyepos.x=%g\n",1);
  fprintf(FILENUM,"%% eyepos.z=%g\n",2*tan(pi/18));
  if (is_scalar(V))
    fprintf(FILENUM,"%% nsteps = %d\n",V);
    fprintf(FILENUM,"%% contours=(");
    fprintf(FILENUM," %.3g",V);
  fprintf(FILENUM,"%% nx = %d xgrid=True\n",m); 
  fprintf(FILENUM," %.3g",x);fprintf(FILENUM,"\n");
  fprintf(FILENUM,"\n%% ny = %d ygrid=True\n",n); 
  fprintf(FILENUM," %.3g",y);fprintf(FILENUM,"\n");
  fprintf(FILENUM,"%% binary=True\n");
  z = fliplr(z');
  save -mat-binary /tmp/temp.mat z
  mtv_cmd = sprintf("system(\"tail -c %.0f /tmp/temp.mat >> %s\")", \
                    8*m*n, file);

  shell_cmd("/home/john/Plotmtv1.4.1/Bin/plotmtv -3d -geom 688x572+80+0 -nodate 
-noframe \
             /tmp/mtv_curves_dat > /dev/null ; rm /tmp/mtv_curves_dat &");

Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:
How to fund new projects:
Subscription information:

reply via email to

[Prev in Thread] Current Thread [Next in Thread]