设为首页 收藏本站
查看: 1511|回复: 0

[经验分享] Python之ipython、notebook、matplotlib安装使用

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-10-11 08:58:41 | 显示全部楼层 |阅读模式
Python之ipython、notebook、matplotlib安装使用

交互式编程不需要创建脚本文件,是通过 Python 解释器的交互模式进来编写代码。

    linux上你只需要在命令行中输入 Python 命令即可启动交互式编程

    Window上在安装Python时已经已经安装了默认的交互式编程客户端

备注:> 中文编码
#!/usr/bin/python# -*- coding: UTF-8 -*-

以下进行逐步安装配置

python 3.5.2, ipython 5.1.0, jupyter notebook, matplotlib

1、安装python3.5

具体安装请参考官方文档。安装程序时注意勾选配置环境变量。https://www.python.org/downloads/windows/

2、升级pip

python -m pip install --upgrade pip

3、使用pip安装ipython

pip.exe install ipython

    交互模式效果如下

D:\tools>ipython
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:01:18) [MSC v.1900 32 bit (Intel)]Type "copyright", "credits" or "license" for more information.
IPython 5.1.0 -- An enhanced Interactive Python.?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.In [1]: print('hello world!')
hello world!In [2]: a = ['Windows','10','Python','3.5.2','ipython','jupyter notebook']In [3]: aOut[3]: ['Windows', '10', 'Python', '3.5.2', 'ipython', 'jupyter notebook']In [4]: for i in a:
   ...:     print(i)
   ...:
Windows10Python3.5.2ipython
jupyter notebookIn [5]:

4、使用pip安装notebook

pip install notebook

    提示已成功安装的包和版本

Installing collected packages: jupyter-core, MarkupSafe, jinja2, jsonschema, nbformat, entrypoints, mistune, nbconvert, tornado, pyzmq, jupyter-client, ipykernel, notebook
  Running setup.py install for MarkupSafe ... done
Successfully installed MarkupSafe-0.23 entrypoints-0.2.2 ipykernel-4.5.0 jinja2-2.8 jsonschema-2.5.1 jupyter-client-4.4.0 jupyter-core-4.2.0 mistune-0.7.3 nbconvert-4.2.0 nbformat-4.1.0 notebook-4.2.3 pyzmq-15.4.0 tornado-4.4.2

    在工作目录下启动notebook

jupyter notebook

D:\tools>jupyter notebook
[W 07:44:23.940 NotebookApp] Widgets are unavailable. Please install widgetsnbextension or ipywidgets 4.0[I 07:44:23.955 NotebookApp] The port 8888 is already in use, trying another port.
[I 07:44:24.143 NotebookApp] Serving notebooks from local directory: D:\tools
[I 07:44:24.143 NotebookApp] 0 active kernels
[I 07:44:24.143 NotebookApp] The Jupyter Notebook is running at: http://localhost:8889/
[I 07:44:24.143 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).

    web

QQ截图20161011085757.png

5、安装画图工具 matplotlib

pip install matplotlib
pip install matplotlib --upgrade

    结果提示

Installing collected packages: cycler, pytz, pyparsing, numpy, python-dateutil, matplotlib
Successfully installed cycler-0.10.0 matplotlib-1.5.3 numpy-1.11.2 pyparsing-2.1.10 python-dateutil-2.5.3 pytz-2016.7

6、测试

b图像测试代码来源:

https://my.oschina.net/bery/blog/203595

import numpy as np
import matplotlib.pyplot as plt
N = 5
menMeans = (20, 35, 30, 35, 27)
menStd =   (2, 3, 4, 1, 2)
ind = np.arange(N)  # the x locations for the groups
width = 0.35       # the width of the bars
fig, ax = plt.subplots()
rects1 = ax.bar(ind, menMeans, width, color='r', yerr=menStd)
womenMeans = (25, 32, 34, 20, 25)
womenStd =   (3, 5, 2, 3, 3)
rects2 = ax.bar(ind+width, womenMeans, width, color='y', yerr=womenStd)
# add some
ax.set_ylabel('Scores')
ax.set_title('Scores by group and gender')
ax.set_xticks(ind+width)
ax.set_xticklabels( ('G1', 'G2', 'G3', 'G4', 'G5') )
ax.legend( (rects1[0], rects2[0]), ('Men', 'Women') )
def autolabel(rects):
    # attach some text labels
    for rect in rects:
        height = rect.get_height()
        ax.text(rect.get_x()+rect.get_width()/2., 1.05*height, '%d'%int(height),
                ha='center', va='bottom')
autolabel(rects1)
autolabel(rects2)
plt.show()

QQ截图20161011085805.png

   
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(9)
y = np.sin(x)
plt.plot(x,y)
plt.show()

QQ截图20161011085811.png

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-284302-1-1.html 上篇帖子: python爬取拉勾网招聘信息并利用pandas做简单数据分析 下篇帖子: python使用递归实现目录遍历 notebook
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表