标签归档:matplotlib

RSS feed of matplotlib

利用matplotlib绘制约数个数统计图

利用Python计算1000以内自然数的约数个数,然后通过matplotlib绘制统计图。

下图为约数个数的散点图及其分布情况的条形图。

Python代码:

import collections
import matplotlib.pyplot as plt

def countDivisors(num):
    ans = 1
    x = 2
    while x * x <= num:
        cnt = 1
        while num % x == 0:
            cnt += 1
            num /= x
        ans *= cnt
        x += 1
    return ans * (1 ...

继续阅读

利用matplotlib绘制Logistic曲线

标准Logistic函数为:

f(x) = 1 / ( 1 + exp(-x) )

其导函数为:

f'(x) = f(x) * ( 1 - f(x) )

下面使用matplotlib绘制逻辑斯蒂函数及其导函数的曲线。

Python代码:

import numpy as np
import matplotlib.pyplot as plt

a = np.linspace(-10, 10, 1000)
b = 1.0 / (1.0  + np.exp(-a ...

继续阅读