windows7下使用64位Python编程、科学计算、绘制图表

来源:互联网 发布:古风静态头像psd源码 编辑:程序博客网 时间:2024/05/21 04:21

介绍windows7 64位系统下使用python。

 

1、下载并安装64版本的python2.7。下载地址:点击打开链接

    一直“下一步”即可安装完成。完成后,就可以使用python GUI编程了。

 

2、下载科学计算扩展包,Numpy。下载地址:点击打开链接

    Numpy 是一个 Python 的扩展模块,通过使用 NumPy,我们可以进行科学计算。NumPy 提供了矩阵、线性代数、傅里叶变换等的解决方法。

    NumPy包含:

        1)N维矩阵对象

        2)线性代数运算功能

        3)傅里叶变换

        4)Fortran代码集成的工具

        5) C++代码集成的工具

3、下载扩展包matplotlib,下载地址:点击打开链接

        matplotlib是一个在python下实现的类matlab 的纯python 的三方库。Matplotlib 可以绘制多种形式的图形包括普通的线图,直方图,饼图,散点图以及误差线图等。

 

 

 

4、简单绘图:

    绘图只需要导入matplotlib扩展包即可:

import matplotlib.pyplot as pltplt.plot([1,2])plt.show()


 

 5、绘制复杂图标例子

 

#!/usr/bin/env python'''Demonstration of LineCollection, PolyCollection, andRegularPolyCollection with autoscaling.For the first two subplots, we will use spirals.  Theirsize will be set in plot units, not data units.  Their positionswill be set in data units by using the "offsets" and "transOffset"kwargs of the LineCollection and PolyCollection.The third subplot will make regular polygons, with the sametype of scaling and positioning as in the first two.The last subplot illustrates the use of "offsets=(xo,yo)",that is, a single tuple instead of a list of tuples, to generatesuccessively offset curves, with the offset given in dataunits.  This behavior is available only for the LineCollection.'''import matplotlib.pyplot as Pfrom matplotlib import collections, axes, transformsfrom matplotlib.colors import colorConverterimport numpy as Nnverts = 50npts = 100# Make some spiralsr = N.array(range(nverts))theta = N.array(range(nverts)) * (2*N.pi)/(nverts-1)xx = r * N.sin(theta)yy = r * N.cos(theta)spiral = zip(xx,yy)# Make some offsetsrs = N.random.RandomState([12345678])xo = rs.randn(npts)yo = rs.randn(npts)xyo = zip(xo, yo)# Make a list of colors cycling through the rgbcmyk series.colors = [colorConverter.to_rgba(c) for c in ('r','g','b','c','y','m','k')]fig = P.figure()a = fig.add_subplot(2,2,1)col = collections.LineCollection([spiral], offsets=xyo,                                transOffset=a.transData)trans = fig.dpi_scale_trans + transforms.Affine2D().scale(1.0/72.0)col.set_transform(trans)  # the points to pixels transform    # Note: the first argument to the collection initializer    # must be a list of sequences of x,y tuples; we have only    # one sequence, but we still have to put it in a list.a.add_collection(col, autolim=True)    # autolim=True enables autoscaling.  For collections with    # offsets like this, it is neither efficient nor accurate,    # but it is good enough to generate a plot that you can use    # as a starting point.  If you know beforehand the range of    # x and y that you want to show, it is better to set them    # explicitly, leave out the autolim kwarg (or set it to False),    # and omit the 'a.autoscale_view()' call below.# Make a transform for the line segments such that their size is# given in points:col.set_color(colors)a.autoscale_view()  # See comment above, after a.add_collection.a.set_title('LineCollection using offsets')# The same data as above, but fill the curves.a = fig.add_subplot(2,2,2)col = collections.PolyCollection([spiral], offsets=xyo,                                transOffset=a.transData)trans = transforms.Affine2D().scale(fig.dpi/72.0)col.set_transform(trans)  # the points to pixels transforma.add_collection(col, autolim=True)col.set_color(colors)a.autoscale_view()a.set_title('PolyCollection using offsets')# 7-sided regular polygonsa = fig.add_subplot(2,2,3)col = collections.RegularPolyCollection(7,                                        sizes = N.fabs(xx)*10.0, offsets=xyo,                                        transOffset=a.transData)trans = transforms.Affine2D().scale(fig.dpi/72.0)col.set_transform(trans)  # the points to pixels transforma.add_collection(col, autolim=True)col.set_color(colors)a.autoscale_view()a.set_title('RegularPolyCollection using offsets')# Simulate a series of ocean current profiles, successively# offset by 0.1 m/s so that they form what is sometimes called# a "waterfall" plot or a "stagger" plot.a = fig.add_subplot(2,2,4)nverts = 60ncurves = 20offs = (0.1, 0.0)yy = N.linspace(0, 2*N.pi, nverts)ym = N.amax(yy)xx = (0.2 + (ym-yy)/ym)**2 * N.cos(yy-0.4) * 0.5segs = []for i in range(ncurves):    xxx = xx + 0.02*rs.randn(nverts)    curve = zip(xxx, yy*100)    segs.append(curve)col = collections.LineCollection(segs, offsets=offs)a.add_collection(col, autolim=True)col.set_color(colors)a.autoscale_view()a.set_title('Successive data offsets')a.set_xlabel('Zonal velocity component (m/s)')a.set_ylabel('Depth (m)')# Reverse the y-axis so depth increases downwarda.set_ylim(a.get_ylim()[::-1])P.show()