zoukankan      html  css  js  c++  java
  • <数据可视化>样例+数据+画图

    1 样例

    1.1样例1

      子图系列

    from pylab import *
    
    def f(x):
        return np.exp(-x) * np.cos(2*np.pi*x)
    
    x1 = np.arange(0.0, 5.0, 0.1)
    x2 = np.arange(0.0, 5.0, 0.02)
    
    plt.figure(1)
    plt.subplot(211)
    plt.plot(x1, f(x1), 'bo', x2, f(x2), 'k')
    
    plt.subplot(212)
    plt.plot(x2, np.cos(2*np.pi*x2),'r-')
    
    plt.show()
    

      

    1.2 样例2

      曲线系列

    from pylab import *
    
    x = np.linspace(-4, 4, 200)
    f1 = np.power(10, x)
    f2 = np.power(np.e, x)
    f3 = np.power(2, x)
    
    plt.plot(x, f1, 'r', x, f2, 'b', x, f3, 'g', linewidth=2)
    plt.axis([-4, 4, -0.5, 8])
    plt.text(1, 7.5, r'$10^x$')
    plt.text(2.2, 7.5, r'$e^x$')
    plt.text(3.2, 7.5, r'$2^x$')
    plt.title('A simple example')
    
    plt.show()
    

      

    2. 实际问题

    2.1 美国出生统计画图

      关于1940至2000年美国出生人口数量的统计数据,第一列表示年份,第二列表示当年男孩的出生人数,第三列表示当年女孩的出生人数。

    数据:

    1940--2002美国出生统计
    
    "year" "boys" "girls"
    1940 1211684 1148715
    1941 1289734 1223693
    1942 1444365 1364631
    1943 1508959 1427901
    1944 1435301 1359499
    1945 1404587 1330869
    1946 1691220 1597452
    1947 1899876 1800064
    1948 1813852 1721216
    1949 1826352 1733177
    "11" 1950 1823555 1730594
    "12" 1951 1923020 1827830
    "13" 1952 1971262 1875724
    "14" 1953 2001798 1900322
    "15" 1954 2059068 1958294
    "16" 1955 2073719 1973576
    "17" 1956 2133588 2029502
    "18" 1957 2179960 2074824
    "19" 1958 2152546 2051266
    "20" 1959 2173638 2071158
    "21" 1960 2179708 2078142
    "22" 1961 2186274 2082052
    "23" 1962 2132466 2034896
    "24" 1963 2101632 1996388
    "25" 1964 2060162 1967328
    "26" 1965 1927054 1833304
    "27" 1966 1845862 1760412
    "28" 1967 1803388 1717571
    "29" 1968 1796326 1705238
    "30" 1969 1846572 1753634
    "31" 1970 1915378 1816008
    "32" 1971 1822910 1733060
    "33" 1972 1669927 1588484
    "34" 1973 1608326 1528639
    "35" 1974 1622114 1537844
    "36" 1975 1613135 1531063
    "37" 1976 1624436 1543352
    "38" 1977 1705916 1620716
    "39" 1978 1709394 1623885
    "40" 1979 1791267 1703131
    "41" 1980 1852616 1759642
    "42" 1981 1860272 1768966
    "43" 1982 1885676 1794861
    "44" 1983 1865553 1773380
    "45" 1984 1879490 1789651
    "46" 1985 1927983 1832578
    "47" 1986 1924868 1831679
    "48" 1987 1951153 1858241
    "49" 1988 2002424 1907086
    "50" 1989 2069490 1971468
    "51" 1990 2129495 2028717
    "52" 1991 2101518 2009389
    "53" 1992 2082097 1982917
    "54" 1993 2048861 1951379
    "55" 1994 2022589 1930178
    "56" 1995 1996355 1903234
    "57" 1996 1990480 1901014
    "58" 1997 1985596 1895298
    "59" 1998 2016205 1925348
    "60" 1999 2026854 1932563
    "61" 2000 2076969 1981845
    "62" 2001 2057922 1968011
    "63" 2002 2057979 1963747
    

     

    代码:

    from pylab import *
    figure(figsize=(8, 6), dpi=100)
    year = []
    boys = []
    girls = []
    n = 1
    with open("1940--2002美国出生统计.txt",'r') as file:
    	while True:
    		lists = file.readline()
    		items = lists.split(" ")
    		if len(items) == 3:
    			if n <= 1 :
    				n += 1
    				continue
    			year.append(int(items[0]))
    			boys.append(int(items[1]))
    			girls.append(int(items[2]))
    		elif len(items) == 4:
    			year.append(int(items[1]))
    			boys.append(int(items[2]))
    			girls.append(int(items[3]))
    		if not lists:
    			break
    plt.plot(year, boys, color="blue", linewidth=3.0, linestyle="-", label="boys")
    plt.plot(year, girls, color="red", linewidth=3.0, linestyle="-", label="girs")
    plt.legend(loc=0)
    mpl.rcParams['font.sans-serif']=['SimHei']
    mpl.rcParams['axes.unicode_minus']=False
    plt.xlabel("年份")
    plt.ylabel("出生人数")
    plt.title('1940--2002美国出生统计')
    savefig("0001",dpi=100)
    plt.show()
    

    图像为:

    2.2 待续 

  • 相关阅读:
    AccessTokenValidation3 源码分析 jwttoken验证流程图
    .net core dump分析
    9102年了,汇总下HttpClient问题,封印一个
    Asp.net 性能监控之压测接口“卡住” 分析
    IdentityServer4源码颁发token分析及性能优化
    博客园设置看板娘和看板猫
    C# winform websocket学习笔记(三)HTML客户端
    C# winform websocket学习笔记(三)winform客户端
    C# winform websocket学习笔记(二)winform服务端
    C# winform websocket学习笔记(一)准备
  • 原文地址:https://www.cnblogs.com/shuimohei/p/10744806.html
Copyright © 2011-2022 走看看