相关工具库很多,都是科学计算的东西:numpy、scipy、pandas、matplotlib、sympy、mayavi2

SciPy官网的介绍

NumPy's array type augments the Python language with an efficient data structure useful for numerical work, e.g., manipulating matrices. NumPy also provides basic numerical routines, such as tools for finding eigenvectors.

SciPy contains additional routines needed in scientific work: for example, routines for computing integrals numerically, solving differential equations, optimization, and sparse matrices.

The matplotlib module produces high quality plots. With it you can turn your data or your models into figures for presentations or articles. No need to do the numerical work in one program, save the data, and plot it with another program.

简要的说:

numpy--定义了数值数组和矩阵类型和它们的基本运算的语言扩展

scipy--使用numpy来做高等数学、信号处理、优化、统计和许多其它科学任务的语言扩展

pandas--对numpy做了进一步封装

matplotlib--python的2D绘图库,提供了类MATLAB的API

mayavi2--python的3D绘图库

sympy---python符号计算库

对sympy的解释比较抽象,运行实例感受一下

>>> import math,numpy,sympy

>>> math.sqrt(8)

2.8284271247461903

>>> math.sqrt(8) * math.sqrt(2)

4.000000000000001

>>> numpy.sqrt(8)

2.8284271247461903

>>> numpy.sqrt(8) * numpy.sqrt(2)

4.0000000000000009

>>> sympy.sqrt(8)

2*sqrt(2)

>>> sympy.sqrt(8) * sympy.sqrt(2)

4

以下内容只需要安装numpy、matplotlib和sympy

Windows安装numpy比较麻烦,有时可能遇到各种错,

搜索numpy,下载对应的系统预编译版本

下载完成用如下类似命令安装即可

pip install "numpy-1.10.4+mkl-cp35-none-win_amd64.whl"

1. 心形的公式

2. 绘制2D心形

1) 通过matplotlib

import matplotlib.pyplot as plt

import numpy as np

# -pi ~ pi, split 256

t = np.linspace(-np.pi, np.pi, 256, endpoint=True)

X = 16 * (np.sin(t))**3

Y = 13 * np.cos(t) - 5 * np.cos(2 * t) - 2 * np.cos(3 * t) - np.cos(4 * t)

# plot at line1 column1

plt.subplot(121)

plt.plot(X, Y)

# -3 ~ 3, step 0.02

x = y = np.arange(-3.0, 3.0, 0.02)

X, Y = np.meshgrid(x, y)

Z = (X**2 + Y**2 - 1)**3 - X**2 * Y**3

# plot at line1 column2

plt.subplot(122)

plt.contour(X, Y, Z)

plt.colorbar()

plt.show()

2) 通过sympy

画等式特别方便

>>> from sympy import symbols,plot_implicit

>>> x,y = symbols('x y')

>>> plot_implicit((x**2 + y**2 - 1)**3 - x**2 * y**3)

3. 绘制3D图形

from mpl_toolkits.mplot3d import Axes3D

from matplotlib import cm

from matplotlib.ticker import LinearLocator, FormatStrFormatter

import matplotlib.pyplot as plt

import numpy as np

def heart_3d(x,y,z):

return (x**2 + (9/4) * y**2 + z**2 - 1)**3 - x**2 * z**3 - (9/80) * y**2 * z**3

def heart_3d_2(x,y,z):

return (2 * x**2 + 2 * y**2 + z**2 - 1)**3 - 0.1 * x**2 * z**3 - y**2 * z**3

def plot_implicit(fn, bbox=(-1.5, 1.5)):

''' create a plot of an implicit function

fn ...implicit function (plot where fn==0)

bbox ..the x,y,and z limits of plotted interval'''

xmin, xmax, ymin, ymax, zmin, zmax = bbox*3

fig = plt.figure()

ax = fig.add_subplot(111, projection='3d')

A = np.linspace(xmin, xmax, 100) # resolution of the contour

B = np.linspace(xmin, xmax, 40) # number of slices

A1, A2 = np.meshgrid(A, A) # grid on which the contour is plotted

for z in B: # plot contours in the XY plane

X, Y = A1, A2

Z = fn(X, Y, z)

cset = ax.contour(X, Y, Z+z, [z], zdir='z', colors=('r',))

# [z] defines the only level to plot

# for this contour for this value of z

for y in B: # plot contours in the XZ plane

X, Z = A1, A2

Y = fn(X, y, Z)

cset = ax.contour(X, Y+y, Z, [y], zdir='y', colors=('red',))

for x in B: # plot contours in the YZ plane

Y, Z = A1, A2

X = fn(x, Y, Z)

cset = ax.contour(X+x, Y, Z, [x], zdir='x',colors=('red',))

# must set plot limits because the contour will likely extend

# way beyond the displayed level. Otherwise matplotlib extends the plot limits

# to encompass all values in the contour.

ax.set_zlim3d(zmin, zmax)

ax.set_xlim3d(xmin, xmax)

ax.set_ylim3d(ymin, ymax)

plt.show()

if __name__ == '__main__':

plot_implicit(heart_3d)

4. 最后通过turtle动态画一个心形

from turtle import *

def curvemove():

for i in range(100):

right(2)

forward(2)

color('red','pink')

begin_fill()

left(140)

forward(111.65)

curvemove()

left(120)

curvemove()

forward(111.65)

end_fill()

done()

refer

python画图心形_通过matplotlib绘制心形相关推荐

  1. 如何用python画数学图案_使用Matplotlib 绘制精美的数学图形例子

    一个最最简单的例子: 绘制一个从 0 到 360 度完整的 SIN 函数图形 import numpy as np import matplotlib.pyplot as pt x = np.aran ...

  2. python画图颜色代码_关于matplotlib:Python:制作从红色到蓝色的颜色条

    我要绘制一系列线(目前总共60条线),以绘制到同一图中以显示某个过程的时间演变.当前已绘制线,因此最早的时间步长以100%红色绘制,最新的时间步长以100%蓝色绘制,中间的时间步长根据时间分别为红色和 ...

  3. python 四象限图_使用matplotlib绘制四象限图

    今天简单研究了一下在python中绘制四象限图的问题,结合前人相关研究成果,绘制出的图效果如下: 绘制这种图的要点是:自己构造新的x轴和y轴,不要用散点图默认的横纵坐标系,并且不要显示原来的横纵坐标系 ...

  4. python 画k线_使用matplotlib绘制k线图

    利用matplotlib.finance绘制K线图时使用关键要点 绘制k线图的核心语句是: import matplotlib.finance as mpf mpf.candlestick_ochl( ...

  5. 用python画数学函数图像教程_使用Matplotlib 绘制精美的数学图形例子

    一个最最简单的例子: 绘制一个从 0 到 360 度完整的 SIN 函数图形 import numpy as np import matplotlib.pyplot as pt x = np.aran ...

  6. Python dataframe绘制饼图_运用matplotlib绘制折线图、散点图、饼图、柱形图的定义代码以及案例详解...

    从导入数据开始 这里我们有一个现成的数据表包,现在我们所处环境是pycharm,安装环境是annaconda3环境,我们将通过这个数据表包来进行数据分析,运用matplotlib绘制折线图.散点图.饼 ...

  7. python turtle笛卡尔心形线_用MATLAB实现心形线

    背景 众所周知,笛卡尔是一位超越时代的数学家.物理学家和思想家.他在数学领域所创造的成就影响着自他之后所有的数学研究,他可以被称为解析几何之父.在哲学和心理学方面,笛卡尔也获得了非凡的成就,他是二元论 ...

  8. python画图颜色代码_python中matplotlib的颜色及线条控制的示例

    下次用python画图的时候选色选点都可以直接参考这边,牛逼!分享给大家,也给自己留个笔记. 参考网址: http://stackoverflow.com/questions/22408237/nam ...

  9. python画图显示中文_Python的matplotlib库画图不能显示中文问题解决

    有两种解决办法: 一种是在代码里设置为能显示中文的字体,如微软雅黑(msyh.ttf)和黑体(simsun.ttc) 如下在要画图的代码前添加: import matplotlib.pyplot as ...

最新文章

  1. centos7搭建nexus
  2. Server.Transfer方法在页面间传值
  3. 中标麒麟linux卸载qt,国产化 银河麒麟编译Qt程序的问题汇总 | 阿拉灯
  4. websocket 发送图片_基于WebSocket的web端IM即时通讯应用的开发
  5. 读《大道至简—是懒人造就了方法 》有感
  6. 如何把备份的bak还原到新的数据库
  7. 订阅发布系统得解耦与冗余
  8. python中的然后_返回,然后等待另一个函数在python中完成
  9. ToString yyyy-MM-dd ,MM 小写的故事。
  10. Docker笔记1 基础概念和镜像
  11. mysql 自定义排序函数_MySQL自定义排序函数FIELD()
  12. C#反射取得方法、属性、变量
  13. [redmine问题回复】redmine安装好后,在什么地方增加cvs配置库CVSROOT
  14. 基于FPGA的DHT11数字温湿度传感器测试
  15. 五,FreeRTOS之——相对延时与绝对延时
  16. html5视频播放器 知乎,6款让人赞不绝口的电脑软件,知乎超10W人推荐,建议悄悄收藏...
  17. STM32c8t6驱动激光雷达(一)
  18. STDMETHOD介绍
  19. oracle的Minus的使用
  20. 翻译:Panda3D Manual/V. Programming with Panda/E. Camera Control

热门文章

  1. 【音视频流媒体】WebRTC 直播超详细介绍
  2. OLAP分析引擎Druid配置文件详解(五):MiddleManager配置文件
  3. 深圳大学计算机专硕和学硕的区别,2021深大考研:学硕专硕的区别
  4. ioppc技术_广东电网有限责任公司河源供电局基于IOPPC线路光纤网络智能态势感知技术研究技术服务等5个项目采购公告...
  5. 两管式出热水被截流 海尔三管大水量真正零冷水入驻天猫
  6. 【亲测有效】微信图片已过期的恢复方法
  7. 电子科技大学格拉斯哥学院基础实践————寝室情况及存在问题
  8. excel vba如何在不打开的情况下获取.pdf文件的打印页码数
  9. 云服务器是干什么的 通俗易懂地解释一下
  10. Scrum立会报告+燃尽图(Beta阶段第二次)