WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 01-23-2017, 12:43 PM
haohaoxuexi1 haohaoxuexi1 is offline
Member
 
Join Date: Sep 2015
Posts: 81
Smile about maplotlib in Vizard

Code:
import matplotlib
matplotlib.use('agg') 
import matplotlib.pyplot as plt

import time
import random

import viz
import viztask

import vizmatplot

viz.go()

#determine size of arrays (number of samples)
MAX_SIZE_OF_ARRAY = 5000

#create arrays
array_x, array_y = [],[]

#fill array with zeros 
for i in range(0,MAX_SIZE_OF_ARRAY):
	array_x.append(0)
	array_y.append(0)
	
###---matplotlib codes---###
fig = plt.figure()	#instantiate pyplot figure
ax = fig.add_subplot(111)	#create axes
ax.axis([0,MAX_SIZE_OF_ARRAY,0,1])	#determine axis limits
line, = ax.plot(array_x,array_y)	#instantiate plot 
matplot = vizmatplot.Show(fig)
matplot.showDrawRate(viz.ON)

def plotter():
	""" task that randomly creates y data while incrementing x data"""
	while True:
		#yield None
		for i in range (0,MAX_SIZE_OF_ARRAY):
			array_x[i] = (i)	
			array_y[i] = (random.random())	
			ax.axis([0, MAX_SIZE_OF_ARRAY, 0, 1])	#make sure the axis limits don't change
			line.set_data(array_x, array_y)	#set the data points
		
			yield None	#wait at least a frame before setting new data points
		#	yield viztask.waitTime(matplot.rate) #or wait draw rate length calculated in module
		
		for b in range(0,MAX_SIZE_OF_ARRAY):	#clear out the arrays 
			array_x[b] = 0
			array_y[b] = 0
			line.set_data(array_x,array_y)	#clear graph by setting all data points to [0,0]			
	
viztask.schedule( plotter() )
this code comes out an error of "RuntimeError: dictionary changed size during iteration", anyone know how to solve it?

the code was from matplotlib website in Vizard webpage.
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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Realistic Light and Shadows Using Vizard and 3DS Max jde Vizard 4 07-13-2012 10:58 AM
Vizard 4 Beta Testing farshizzo Announcements 0 02-01-2011 10:46 AM
Vizard 4 Beta Testing farshizzo Vizard 0 02-01-2011 10:46 AM
Vizard tech tip: Using the Python Imaging Library (PIL) Jeff Vizard 0 03-23-2009 11:13 AM
Vizard tech tip: Text to Speech Jeff Vizard 1 01-15-2009 09:39 PM


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


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