Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Python plotting

Posted on 2013-01-10
2
Medium Priority
?
340 Views
Last Modified: 2013-01-10
Hi

Can anybody tell me why the following code won't work? I get a syntax error on

plt.figure()

This is the code:

import matplotlib.pyplot as plt
import math

def plotBinomial():
      prob = input( 'Enter probability of success: ')
      n = input( 'Enter the number of successes: ')
      Nmax = input( 'Enter the maximum number of trials: ')

      x = []
      y = []
      
      for N in range( n, Nmax + 1 ):
            x.append( N )
            y.append( probability( prob, n, N )
            
      plt.figure()
      plt.title( 'Varying N and probability p = ' + str( prob ) )
      plt.xlabel( 'N' )
      plt.ylabel( 'Probability' )
      plt.grid( True )
      plt.plot( x, y )
      plt.show()
      plt.close()

def probability( prob, n, N ):
    nCr = math.factorial( N ) / ( math.factorial( n ) * math.factorial( N - n ) )
    P = nCr * ( prob**n ) * ( 1 - prob )**( N - n )
    return P
0
Comment
Question by:IssacJones
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 17

Accepted Solution

by:
gelonida earned 1200 total points
ID: 38762646
You forgot a closing parenthesis in the line before.


            y.append( probability( prob, n, N )

should be
            y.append( probability( prob, n, N ))

This is a rather classical issue with syntax checking.
The parser doesn't know whether you forgot the closing parenthesis or whether you wanted to write a multi-line statement.
0
 

Author Closing Comment

by:IssacJones
ID: 38762795
Excellent!
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show the steps for installing Python on Ubuntu Operating System. I have created a virtual machine with Ubuntu Operating system 8.10 and this installing process also works with upgraded version of Ubuntu OS. For installing Py…
Sequence is something that used to store data in it in very simple words. Let us just create a list first. To create a list first of all we need to give a name to our list which I have taken as “COURSE” followed by equals sign and finally enclosed …
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question