python交互式和文件式区别_Python交互式编程

python交互式和文件式区别_Python交互式编程Python 之 ipython notebook matplotlib 安装使用交互式编程不需要创建脚本文件 是通过 Python 解释器的交互模式进来编写代码 linux 上你只需要在命令行中输入 Python 命令即可启动交互式编程 Window 上在安装 Python 时已经已经安装了默认的交互式编程客户端备注 中文编码 usr bin python coding UTF 8 以

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、升级pippython -m pip install –upgrade pip

3、使用pip安装ipythonpip.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安装notebookpip 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

在工作目录下启动notebookjupyter 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

wKiom1f7Sg6RiIrbAACIpDwBkwQ893.png-wh_500x0-wm_3-wmp_4-s_1936398854.png

5、安装画图工具 matplotlibpip 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图像测试代码来源: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()

wKiom1f7SguwFLYyAAD7gDkFtCk735.png-wh_500x0-wm_3-wmp_4-s_2246651733.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()

wKioL1f7SgzwCqivAAB_1ji8cbI398.png-wh_500x0-wm_3-wmp_4-s_2143053922.png

原文地址:http://bennychen.blog.51cto.com//

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/208964.html原文链接:https://javaforall.net

(0)
上一篇 2026年3月19日 上午10:21
下一篇 2026年3月19日 上午10:22


相关推荐

  • redis面试题总结

    redis面试题总结

    2021年10月31日
    44
  • Truncate用法详解[通俗易懂]

    Truncate用法详解[通俗易懂]前言:当我们想要清空某张表时,往往会使用truncate语句。大多时候我们只关心能否满足需求,而不去想这类语句的使用场景及注意事项。本篇文章主要介绍truncate语句的使用方法及注意事项。1.truncate使用语法truncate的作用是清空表或者说是截断表,只能作用于表。truncate的语法很简单,后面直接跟表名即可,例如:truncatetabletbl_name …

    2025年8月20日
    5
  • python虚拟环境安装和配置[通俗易懂]

    python虚拟环境安装和配置[通俗易懂]http://blog.csdn.net/pipisorry/article/details/47008981AnacondaConda是Continuum公司发布的Anaconda里边配备的一个包管理器。Conda让你更加方便地安装和管理各种扩展包和运行环境,同时支持Windows,MacOSX以及Linux。安装下载Python3版本[https://w…

    2022年10月19日
    6
  • 思科下一代模拟器EVE-NG安装

    思科下一代模拟器EVE-NG安装思科模拟器最早10年前接触过CiscoPacketTracer,后来发展的GNS3,不过一直只支持思科的设备,而EVE最近几年开始火了起来,不仅支持思科设备,而且支持众多的华为,山石等国产设备。EVE-NG官网:https://www.eve-ng.net/EVE-NG官网下载页:Download下载其中的社区版OVA和window客户端即可官方的下载连接如下社区版的OVF文件https://mega.nz/file/qlt3zK7Q#LZdFhSxJPCpd4-QNyu5U6ia

    2022年6月3日
    83
  • Linux计划任务「建议收藏」

    Linux计划任务「建议收藏」计划任务的安排方式分两种:一种是定时性的,也就是例行。就是每隔一定的周期就要重复来做这个事情一种是突发性的,就是这次做完了这个事,就没有下一次了,临时决定,只执行一次的任务at和crontab这

    2022年7月4日
    21
  • ArcGIS相交闭合矩形线转面

    ArcGIS相交闭合矩形线转面ArcGIS 相交闭合矩形线转面如图为两条自我闭合且相交的线现在想将其转换成如下图所示的两个独立的多边形 但直接使用 ArcGIS 的 要素转面 工具会生成五个独立的多边形 如图所示 属性记录也为 5 条 现使用另一种方式进行转换 1 要素转 json 使用工具箱中的 要素转 json 工具将线要素转成 json 的文件 2 修改 json 代码将 json 文件用编辑器打开 vs not

    2025年9月14日
    6

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号