zoukankan      html  css  js  c++  java
  • pathon math lib

    numpy + SciPy + IPython + matplotlib

    - example of plot: http://matplotlib.sourceforge.net/

    import matplotlib.pyplot as plt
    import numpy as np

    x,y = np.random.randn(2,100)
    fig = plt.figure()
    ax1 = fig.add_subplot(211)
    ax1.xcorr(x, y, usevlines=True, maxlags=50, normed=True, lw=2)
    ax1.grid(True)
    ax1.axhline(0, color='black', lw=2)

    ax2 = fig.add_subplot(212, sharex=ax1)
    ax2.acorr(x, usevlines=True, normed=True, maxlags=50, lw=2)
    ax2.grid(True)
    ax2.axhline(0, color='black', lw=2)

    plt.show()

    - save graph to file: http://stackoverflow.com/questions/4325733/save-a-subplot-in-matplotlib
    import matplotlib.pyplot as plt
    import matplotlib as mpl
    import numpy as np

    # Make an example plot with two subplots...
    fig
    = plt.figure()
    ax1
    = fig.add_subplot(2,1,1)
    ax1
    .plot(range(10), 'b-')

    ax2
    = fig.add_subplot(2,1,2)
    ax2
    .plot(range(20), 'r^')

    # Save the full figure...
    fig
    .savefig('full_figure.png')

    # Save just the portion _inside_ the second axis's boundaries
    extent
    = ax2.get_window_extent().transformed(fig.dpi_scale_trans.inverted())
    fig
    .savefig('ax2_figure.png', bbox_inches=extent)

    # Pad the saved area by 10% in the x-direction and 20% in the y-direction
    fig
    .savefig('ax2_figure_expanded.png', bbox_inches=extent.expanded(1.1, 1.2))

    -- plot 3d data: http://matplotlib.sourceforge.net/plot_directive/mpl_examples/mplot3d/lines3d_demo.py

    import matplotlib as mpl
    from mpl_toolkits.mplot3d import Axes3D
    import numpy as np
    import matplotlib.pyplot as plt

    mpl.rcParams['legend.fontsize'] = 10

    fig = plt.figure()
    ax = fig.gca(projection='3d')
    theta = np.linspace(-4 * np.pi, 4 * np.pi, 100)
    z = np.linspace(-2, 2, 100)
    r = z**2 + 1
    x = r * np.sin(theta)
    y = r * np.cos(theta)
    ax.plot(x, y, z, label='parametric curve')
    ax.legend()

    plt.show()

    -- PIL load & save image
    import Image , ImageDraw

    im = Image.open(infile)
    im.save(outfile, "JPEG")
    draw = ImageDraw.Draw(im) #FAIL to display!

    -- plot image loaded by PIL: (FAIL!)
    import matplotlib.pyplot as plt
    import matplotlib.image as mpimg
    import numpy as np
    s='B:\\3DSolar_ApplTest\\ATS201107\\0720\\WISI0003_sawMark0degLargeThan15\\pair0\\top\\out.tif'
    img=mpimg.imread(s)
    imgplot = plt.imshow(img)
    Axes3D.plot_surface(
  • 相关阅读:
    2-2. 然后是几点(15)
    2-1. 厘米换算英尺英寸(15)
    2-0. 整数四则运算(10)
    忙碌的下半学期
    ACM 第十九天
    ACM 第十八天
    ACM 第十七天
    凸包模板
    极角排序常用方法
    ACM 第十六天
  • 原文地址:https://www.cnblogs.com/cutepig/p/2131344.html
Copyright © 2011-2022 走看看