Python 3 简单编程 画曲线图帮助!
曲线图---
代码----from math import factorial
import numpy as np
import matplotlib.pyplot as plt
#
def fact(n):
return factorial(n)
#Catalan
def cat_direct(n):
return fact(2*n) // fact(n 1) // fact(n)
max = 20
nList = range(25)
valList = []
print "Enter the limit for Catalan numbers to be printed: 10000000000"
for i in nList:
if i <= max:
val = cat_direct(i)
valList.append(val)
print "C %s is:"%i, val
else:
print "C %s is:"%i, 10000000000
valList.append(10000000000)
#---曲线
plt.plot(nList,valList, 'ro')
plt.axis([0, 25, 0, 10000000000])
plt.xlabel("n")
plt.ylabel("Catalan")
plt.title("Cn 1 = 2*(2n 1)*Cn