On Tue, Jan 18, 2011 at 5:33 PM, sgee <jaakko....@gmail.com> wrote:

>
> I'm a CFD student and I wish to learn to make high-quality plots from my
> calculations using matplotlib. However, I'm a complete novice in using
> matplotlib and python and I didn't find any earlier posts so here goes.
>
> I have data form Ansys Fluent in the following form
> continuity     x-velocity           y-velocity          energy
> k                       epsilon
> 1                 0.00011115784  1.5359586e-07  1.0506172e-07
> 0.0032920227
> 0.40809903
> 1                 0.16584706        0.0047719572   2.7355736e-07
> 0.026478255      0.19814095
> 0.5674         0.044237841      0.0026294924   2.8202695e-07   0.030139321
> 0.13935529
>
> The first line is for the first iteration, the second line for the second
> iteration etc. Basically, I would like to have plot this data and have a
> picture like  http://openfoamwiki.net/images/f/ff/Pump_residuals.png this
>
> Any help would be much appreciated.
>
> BR Jack
>

Jack,

First, you would load your data using numpy's loadtxt() function.  You can
tell loadtxt() to skip the first line since it is a header.  This will give
you a 2-D array (n rows and 6 columns) where n is the number of iterations.

You can then plot the data using matplotlib's plot command (or semilogy to
automatically get y-log scaling), passing in the first column for the x
data, and then the other columns for the y data.

So, your code would look something like this:


import numpy as np
import matplotlib.pyplot as plt

data = np.loadtxt('foobar.txt', skiprows=1)

plt.semilogy(data[:, 0], data[:, 1:])
plt.xlabel('Iteration')
plt.ylabel('Residuals')
plt.legend(['Ux_0', 'Uy_0', 'p_0', 'k_0', 'epsilon_0'])
plt.show()


That should get you a similar plot.  There are more things you can do to
control various aspects, but this should get you a good start.

I hope this helps!
Ben Root
------------------------------------------------------------------------------
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand 
malware threats, the impact they can have on your business, and how you 
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to