WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 09-01-2006, 10:49 PM
tobin tobin is offline
WorldViz Team Member
 
Join Date: Feb 2003
Posts: 251
Matplotlib - Introduction

While past versions of Vizard have been compatible with Matplotlib and other 3rd party add-on toolkits, R3 is pre-configured to make the process easy—just as if you were installing them on an official Python.org release.

Matplotlib is a combination of NumPy and PyLab that together gives you a very “Matlab” like environment for generating publication quality figures. You can output to raster formats (e.g., PNG, TIFF, JPG) immediately in a pop-up window or to vector (e.g, EPS, PS) formats that are saved as files. The style of graphs and syntax for creating them—especially when combined with the added Python language constructs through NumPy—will be very familiar to users of Matlab.

Unfortunately, it seems versions across the different contributing packages is important so R3 requires a particular combination of these 3rd party packages. We’ve mirrored these downloads so that you don’t have to try and find them. These links and links to the packages home web pages are included below.

Limitations:
Displaying an interactive figure (i.e., using Matplotlib's show() command) is a blocking command and Vizard will halt until the window is closed. Saving figures to the disk does not have this problem, and raster formats can be read from disk and then displayed as textures if needed for certain scenarios.

Installing
  1. Download and install numpy-0.9.5.win32-py2.4.exe
  2. Download and install wxPython2.6-win32-ansi-2.6.3.3-py24.exe
  3. Download and install matplotlib-0.87.1.win32-py2.4.exe

Configuring
You need to modify lines 29 & 30 in the file called “matplotlibrc”, which is found in the Vizard30\bin\lib\site-packages\matplotlib\mpl-data folder. Change them to read:

Code:
backend      : WXAgg     
numerix      : numpy      # numpy, Numeric or numarray
Testing
Restart Vizard, and then paste the following into an empty Vizard script window and run:

Code:
from pylab import *

t = arange(0.0, 2.0, 0.01)
s = sin(2*pi*t)
plot(t, s, linewidth=1.0)

xlabel('time (s)')
ylabel('voltage (mV)')
title('About as simple as it gets, folks')
grid(True)
show()
Going deeper:

Matplotlib
Matplotlib’s homepage
Useful tutorial
More examples

NumPy
NumPy’s homepage
Users guide
Reply With Quote
  #2  
Old 06-02-2010, 09:50 AM
ptjt255 ptjt255 is offline
Member
 
Join Date: Oct 2008
Posts: 24
Hi,

I have downloaded and installed numpy, wxPython and matplotlib, but when I run your example code, I keep getting the following error message:

Quote:
ImportError: No module named pylab
I have checked and the pylab module is in the matplotlib folder, so I am not sure where I'm going wrong.

Any help would be much appreciated.

Best wishes,
Catherine.
Reply With Quote
  #3  
Old 06-02-2010, 11:08 AM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,449
Is your matplotlib folder in Vizard's site-packages folder?
Reply With Quote
  #4  
Old 06-03-2010, 02:43 AM
ptjt255 ptjt255 is offline
Member
 
Join Date: Oct 2008
Posts: 24
Yes. the matplotlib folder is in Vizard;s site-packages folder.

Thanks,
Catherine.
Reply With Quote
  #5  
Old 06-03-2010, 03:25 AM
ptjt255 ptjt255 is offline
Member
 
Join Date: Oct 2008
Posts: 24
Error Message

Attached is the error I get when I run the pylab source file in case this helps.

Many thanks,
Catherine.

Click image for larger version

Name:	Error.png
Views:	388
Size:	70.0 KB
ID:	373
Reply With Quote
  #6  
Old 06-03-2010, 10:58 AM
Gladsomebeast Gladsomebeast is offline
Member
 
Join Date: Mar 2005
Location: Isla Vizta, CA
Posts: 397
Just a guess, but try re-installing numpy as a module in that package is not right according to the screenshot you posted.
__________________
Paul Elliott
WorldViz LLC
Reply With Quote
  #7  
Old 06-04-2010, 01:01 AM
ptjt255 ptjt255 is offline
Member
 
Join Date: Oct 2008
Posts: 24
I've tried re-installing everything and I am still getting the error:

Quote:
ImportError: No module named pylab
Any thoughts?

Many thanks,
Catherine.
Reply With Quote
  #8  
Old 06-04-2010, 01:35 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,449
Try un-installing all those packages through Windows add/remove programs. Then download and run these more recent installers.

matplotlib-0.98.3.win32-py2.4.exe
numpy-1.2.1-win32-superpack-python2.4.exe
wxPython2.8-win32-ansi-2.8.9.2-py24.exe

Make sure they all find Vizard's python installation. Do you still have the same problem?
Reply With Quote
  #9  
Old 06-05-2010, 12:16 AM
ptjt255 ptjt255 is offline
Member
 
Join Date: Oct 2008
Posts: 24
I have managed to get pylab working, which is great news, thanks for all of your help.

I am now trying to convert my MatLab code, which is:

Quote:
dir = input('Path: ');
filename = input('Filename: ');
path = strcat(dir,filename);
eval(['data = textread(path,'''',''headerlines'',1);']);

A = []; B = [];

w = find(data(:,5) == 0);

b = find(data(w,9) == 4);
b1 = data(b,12);
c = find(data(w,9) == 5);
c1 = data(c,12);
d = find(data(w,9) == 6);
d1 = data(d,12);

A = [A; b1(1) c1(1) d1(1)]

carvscar = mean(A)* 2.23693629
ccnorm = 29.41;
ccnorm2 = 27.09;
ccnorm3 = 18.67;
ccnorm4 = 10.97;

x = find(data(:,5) == 2);

e = find(data(x,9) == 4);
e1 = data(e,12);
f = find(data(x,9) == 5);
f1 = data(f,12);
g = find(data(x,9) == 6);
g1 = data(g,12);

B = [B; e1(1) f1(1) g1(1)]

subplot(2,2,[1 3]); bar([carvscar, ccnorm, ccnorm2,ccnorm3,ccnorm4],'FaceColor',[0 0.5 0],'BarWidth',0.5)
subplot(2,2,[1 3]);title(strcat('Car vs Car'));ylabel('Speed Error (mph)','FontSize',11);ylim([0 70])
set(gca,'XTickLabel',{'Your Result';'6-7 year olds';'8-9 year olds';'10-11 year olds';'Adults'})

if data(x,7) == 2 % Truck
carvslorry = mean(B)*2.23693629
clnorm = 54.47;
clnorm2 = 38.81;
clnorm3 = 40.24;
clnorm4 = 15.25;
subplot(2,2,[2 4]); bar([carvscar, clnorm, clnorm2,clnorm3,clnorm4],'FaceColor',[0 0 0.5],'BarWidth',0.5); hold on;
subplot(2,2,[2 4]);ylabel('Speed Error (mph)','FontSize',11);title(strcat('Faster Car vs Slower Truck'));ylim([0 70]);
set(gca,'XTickLabel',{'Your Result';'6-7 year olds';'8-9 year olds';'10-11 year olds';'Adults'})
elseif data(x,7) == 1 % Motorbike
carvsbike = mean(B)*2.23693629
cbnorm = 10; % fictional speed difference, need to get data from Damian
subplot(2,2,[2 4]); bar([carvscar, cbnorm],'FaceColor',[0 0 0.5],'BarWidth',0.5); hold on;
subplot(2,2,[2 4]);ylabel('Speed Error (mph)','FontSize',11);title(strcat('Faster Car vs Slower Motorbike'));ylim([0 70]);
set(gca,'XTickLabel',{'Your Result';'Adults'})
end
I have figured out that to perform the open file procedure it's:

Quote:
dir = 'C:\\Data'
filename = input('Filename: ')
data = open(dir + filename + '.jnk', 'w')
But I can't figure out what the equivelent to:

Quote:
w = find(data(:,5) == 0);
is?

Many thanks!
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 05:23 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Copyright 2002-2018 WorldViz LLC