花纹的生成可以使用贴图的方式,同样也可以使用方程,本文列出了几种常用曲线的方程式,以取代贴图方式完成特定花纹的生成。

注意极坐标的使用.................

前面部分基础资料,参考:Python:Matplotlib 画曲线和柱状图(Code)

Pyplot教程:https://matplotlib.org/gallery/index.html#pyplots-examples

顾名思义,蝴蝶曲线(Butterfly curve )就是曲线形状如同蝴蝶。蝴蝶曲线如图所示,以方程描述,是一条六次平面曲线。如果大家觉得这个太过简单,别着急,还有第二种。如图所示,以方程描述,这是一个极坐标方程。通过改变这个方程中的变量θ,可以得到不同形状与方向的蝴蝶曲线。如果再施以复杂的组合和变换,我们看到的就完全称得上是一幅艺术品了。

Python代码:

import numpy as np
import matplotlib.pyplot as plt
import os,sys,caffeimport matplotlib as mpl
from mpl_toolkits.mplot3d import Axes3D  #draw lorenz attractor
# %matplotlib inline
from math import sin, cos, pi
import mathdef mainex():#drawSpringCrurve();#画柱坐标系螺旋曲线#HelicalCurve();#采用柱坐标系#尖螺旋曲线#Votex3D();#phoenixCurve();#ButterflyCurve();#ButterflyNormalCurve();#dicareCurve2d();#WindmillCurve3d();#HelixBallCurve();#球面螺旋线#AppleCurve();#HelixInCircleCurve();#使用scatter,排序有问题seperialHelix();def drawSpringCrurve():#碟形弹簧#圓柱坐标 #方程:#import matplotlib as mpl#from mpl_toolkits.mplot3d import Axes3D#import numpy as np#import matplotlib.pyplot as pltmpl.rcParams['legend.fontsize'] = 10;fig = plt.figure();ax = fig.gca(projection='3d');# Prepare arrays x, y, z#theta = np.linspace(-4 * np.pi, 4 * np.pi, 100)#z = np.linspace(-2, 2, 100)#r = z**2 + 1t = np.arange(0,100,1);r = t*0 +20;theta = t*3600 ;z = np.arange(0,100,1);for i in range(100):z[i] =(sin(3.5*theta[i]-90))+24*t[i];x = r * np.sin(theta);y = r * np.cos(theta);ax.plot(x, y, z, label='SpringCrurve');ax.legend();plt.show();def HelicalCurve():#螺旋曲线#采用柱坐标系t = np.arange(0,100,1);r =t ;theta=10+t*(20*360);z =t*3;x = r * np.sin(theta);y = r * np.cos(theta);mpl.rcParams['legend.fontsize'] = 10;fig = plt.figure();ax = fig.gca(projection='3d');ax.plot(x, y, z, label='HelicalCurve');ax.legend();plt.show();def ButterflyCurve():#蝶形曲线,使用球坐标系#或许公式是错误的,应该有更加复杂的公式t = np.arange(0,4,0.01);r = 8 * t;theta = 3.6 * t * 2*1 ;phi   = -3.6 * t * 4*1;x = t*1;y = t*1;#z = t*1;z =0for i in range(len(t)):x[i] = r[i] * np.sin(theta[i])*np.cos(phi[i]);y[i] = r[i] * np.sin(theta[i])*np.sin(phi[i]);#z[i] = r[i] * np.cos(theta[i]);mpl.rcParams['legend.fontsize'] = 10;fig = plt.figure();ax = fig.gca(projection='3d');ax.plot(x, y, z, label='ButterflyCurve');#ax.scatter(x, y, z, label='ButterflyCurve');ax.legend();plt.show();def ButterflyNormalCurve():#蝶形曲线,使用球坐标系#或许公式是错误的,应该有更加复杂的公式#螺旋曲线#采用柱坐标系#t = np.arange(0,100,1);theta=np.arange(0,6,0.1);#(0,72,0.1);r =theta*0;z =theta*0;x =theta*0;y =theta*0;for i in range(len(theta)):r[i] = np.power(math.e,sin(theta[i]))- 2*cos(4*theta[i]) + np.power( sin(1/24 * (2*theta[i] -pi ) ) , 5 );#x[i] = r[i] * np.sin(theta[i]);#y[i] = r[i] * np.cos(theta[i]);x = r * np.sin(theta);y = r * np.cos(theta);mpl.rcParams['legend.fontsize'] = 10;fig = plt.figure();ax = fig.gca(projection='3d');ax.plot(x, y, z, label='ButterflyNormalCurve');ax.legend();plt.show();def phoenixCurve():#蝶形曲线,使用球坐标系t = np.arange(0,100,1);r = 8 * t;theta = 360 * t * 4 ;phi   = -360 * t * 8;x = t*1;y = t*1;z = t*1;for i in range(len(t)):x[i] = r[i] * np.sin(theta[i])*np.cos(phi[i]);y[i] = r[i] * np.sin(theta[i])*np.sin(phi[i]);z[i] = r[i] * np.cos(theta[i]);mpl.rcParams['legend.fontsize'] = 10;fig = plt.figure();ax = fig.gca(projection='3d');ax.plot(x, y, z, label='phoenixCurve');ax.legend();plt.show();def dicareCurve2d():r = np.arange(0, 2, 0.01)theta = 2 * np.pi * rax = plt.subplot(111, projection='polar')ax.plot(theta, r)ax.set_rmax(2)ax.set_rticks([0.5, 1, 1.5, 2])  # Less radial ticksax.set_rlabel_position(-22.5)  # Move radial labels away from plotted lineax.grid(True)ax.set_title("dicareCurve2d", va='bottom')plt.show();def WindmillCurve3d():#风车曲线t = np.arange(0,2,0.01);r =t*0+1 ;#r=1 ang =36*t;#ang =360*t;s =2*pi*r*t;x = t*1;y = t*1;for i in range(len(t)):x[i] = s[i]*cos(ang[i]) +s[i]*sin(ang[i]) ;y[i] = s[i]*sin(ang[i]) -s[i]*cos(ang[i]) ;z =t*0;mpl.rcParams['legend.fontsize'] = 10;fig = plt.figure();ax = fig.gca(projection='3d');ax.plot(x, y, z, label='WindmillCurve3d');ax.legend();plt.show();def HelixBallCurve():#螺旋曲线,使用球坐标系t = np.arange(0,2,0.005);r =t*0+4 ;theta =t*1.8 phi =t*3.6*20x = t*1;y = t*1;z = t*1;for i in range(len(t)):x[i] = r[i] * np.sin(theta[i])*np.cos(phi[i]);y[i] = r[i] * np.sin(theta[i])*np.sin(phi[i]);z[i] = r[i] * np.cos(theta[i]);mpl.rcParams['legend.fontsize'] = 10;fig = plt.figure();ax = fig.gca(projection='3d');ax.plot(x, y, z, label='HelixBallCurve');ax.legend();plt.show();def seperialHelix():#螺旋曲线,使用球坐标系t = np.arange(0,2,0.1);n = np.arange(0,2,0.1);r =t*0+4 ;theta =n*1.8 ;phi =n*3.6*20;x = t*0;y = t*0;z = t*0;for i in range(len(t)):x[i] = r[i] * np.sin(theta[i])*np.cos(phi[i]);y[i] = r[i] * np.sin(theta[i])*np.sin(phi[i]);z[i] = r[i] * np.cos(theta[i]);mpl.rcParams['legend.fontsize'] = 10;fig = plt.figure();ax = fig.gca(projection='3d');ax.plot(x, y, z, label='ButterflyCurve');ax.legend();plt.show();def AppleCurve():#螺旋曲线t = np.arange(0,2,0.01);l=2.5 b=2.5 x =  t*1;y =  t*1;z =0;#z=t*0;n = 36for i in range(len(t)):x[i]=3*b*cos(t[i]*n)+l*cos(3*t[i]*n) y[i]=3*b*sin(t[i]*n)+l*sin(3*t[i]*n)#x = r * np.sin(theta);#y = r * np.cos(theta);mpl.rcParams['legend.fontsize'] = 10;fig = plt.figure();ax = fig.gca(projection='3d');ax.plot(x, y, z, label='AppleCurve');ax.legend();plt.show();def HelixInCircleCurve():#园内螺旋曲线#采用柱坐标系t = np.arange(-1,1,0.01);theta=t*36 ;#360 deta 0.005鸟巢网 #36 deta 0.005 圆内曲线x =  t*1;y =  t*1;z =  t*1;r =  t*1;n = 1.2for i in range(len(t)):r[i]=10+10*sin(n*theta[i]);z[i]=2*sin(n*theta[i]);x[i] = r[i] * np.sin(theta[i]);y[i] = r[i] * np.cos(theta[i]);mpl.rcParams['legend.fontsize'] = 3;fig = plt.figure();ax = fig.gca(projection='3d');ax.plot(x, y, z, label='HelixInCircleCurve');#ax.scatter(x, y, z, label='HelixInCircleCurve');ax.legend();plt.show();def Votex3D():def midpoints(x):sl = ()for i in range(x.ndim):x = (x[sl + np.index_exp[:-1]] + x[sl + np.index_exp[1:]]) / 2.0sl += np.index_exp[:]return x# prepare some coordinates, and attach rgb values to eachr, g, b = np.indices((17, 17, 17)) / 16.0rc = midpoints(r)gc = midpoints(g)bc = midpoints(b)# define a sphere about [0.5, 0.5, 0.5]sphere = (rc - 0.5)**2 + (gc - 0.5)**2 + (bc - 0.5)**2 < 0.5**2# combine the color componentscolors = np.zeros(sphere.shape + (3,))colors[..., 0] = rccolors[..., 1] = gccolors[..., 2] = bc# and plot everythingfig = plt.figure();ax = fig.gca(projection='3d');ax.voxels(r, g, b, sphere,facecolors=colors,edgecolors=np.clip(2*colors - 0.5, 0, 1),  # brighterlinewidth=0.5);ax.set(xlabel='r', ylabel='g', zlabel='b');plt.show();def drawFiveFlower():theta=np.arange(0,2*np.pi,0.02)  #plt.subplot(121,polar=True)  #plt.plot(theta,2*np.ones_like(theta),lw=2)  #plt.plot(theta,theta/6,'--',lw=2)  #plt.subplot(122,polar=True)  plt.subplot(111,polar=True)  plt.plot(theta,np.cos(5*theta),'--',lw=2)  plt.plot(theta,2*np.cos(4*theta),lw=2)  plt.rgrids(np.arange(0.5,2,0.5),angle=45)  plt.thetagrids([0,45,90]);plt.show(); if __name__ == '__main__':import argparsemainex();

画图结果:

  

  

   

   

    

ProE常用曲线方程:Python Matplotlib 版本代码(蝴蝶曲线)相关推荐

  1. python 画蝴蝶_ProE常用曲线方程:Python Matplotlib 版本代码(蝴蝶曲线)

    花纹的生成可以使用贴图的方式,同样也可以使用方程,本文列出了几种常用曲线的方程式,以取代贴图方式完成特定花纹的生成. 注意极坐标的使用................. 顾名思义,蝴蝶曲线(Butte ...

  2. 蝴蝶曲线python_ProE常用曲线方程:Python Matplotlib 版本代码(蝴蝶曲线)

    花纹的生成可以使用贴图的方式,同样也可以使用方程,本文列出了几种常用曲线的方程式,以取代贴图方式完成特定花纹的生成. 注意极坐标的使用................. 顾名思义,蝴蝶曲线(Butte ...

  3. ProE常用曲线方程:Python Matplotlib 版本代码(玫瑰曲线)

    Pyplot教程:https://matplotlib.org/gallery/index.html#pyplots-examples 玫瑰曲线 文字描述 平面内,围绕某一中心点平均分布整数个正弦花瓣 ...

  4. ProE复杂曲线方程:Python Matplotlib 版本代码(L系统,吸引子和分形)

    对生长自动机的研究由来已久,并在计算机科学等众多学科中,使用元胞自动机的概念,用于生长模拟.而复杂花纹的生成,则可以通过重写一定的生长规则,使用生成式来模拟自然纹理.当然,很多纹理是由人本身设计的,其 ...

  5. python蝴蝶代码_ProE常用曲線方程:Python Matplotlib 版本代碼(蝴蝶曲線)

    花紋的生成可以使用貼圖的方式,同樣也可以使用方程,本文列出了幾種常用曲線的方程式,以取代貼圖方式完成特定花紋的生成. 注意極坐標的使用................. 顧名思義,蝴蝶曲線(Butte ...

  6. 显示2位小数 python3_自动化常用语言python,版本3和2有何变化?

    黑马程序员视频库 播妞微信号:boniu236 传智播客旗下互联网资讯.学习资源免费分享平台 Python 3 代表 Python 语言进化的一个产物,所以它不会执行大多数针对 Python 2.x ...

  7. python五角星编程代码绘制

    大家好,我是你们的好朋友,今天继续分享 Python的编程知识. 在 Python中,有一个非常强大的数据可视化工具: database. dl (),其中有一个功能就是可以绘制五角星. 什么是五角星 ...

  8. python1000个常用代码-1000个常用的Python库和示例代码

    下面是programcreek通过分析大量开源代码,提取出的最常用的python库. 1. sys (4627) 2. os(4088) 3. re(3563) 4. time(3195) 5. da ...

  9. 技巧篇:常用的python代码汇总

    一些常用的python代码合集,方便检索引用 模块1:读写excel文件 from datetime import datetime import odps import xlwt import os ...

最新文章

  1. 使用iText库创建PDF文件
  2. windows下的sysprep
  3. 消息发送 C语言版和 Visual Basic Script版
  4. maven jetty 插件 允许修改 js
  5. 2019-02-24-算法-进化
  6. Redis进阶之持久化
  7. postgresql c语言,任意语言访问PostgreSQL:C语言接口
  8. gateway请求拦截_gateway 网关(转发,跨域,拦截器等)
  9. OpenCV-图像金字塔cv::buildPyramid
  10. 常州模拟赛d7t2 数组
  11. java 多线程 面试题整理(更新......)
  12. Android应用的persistent属性
  13. [电路笔记]二端口网络
  14. Android崩溃治理
  15. MWC 2018前瞻:三星华为诺基亚们会展示这些黑科技!
  16. 程序人生 - 库克:苹果收取 30% 佣金很合理!
  17. PicPick 5.1.3 中文版,一个全功能的屏幕截图工具,图像编辑器,颜色选择器
  18. 安卓SSL证书格式:pfx转换BKS格式证书
  19. Scott Hanselman的2006 Windows最终开发者和高级用户工具列表
  20. 【数字设计】芯动科技|芯原科技_2023届_笔试面试题目分享

热门文章

  1. 迷失的毕业生——小余答疑(一)
  2. 【Coursera】SecondWeek(2)
  3. FPS, VSync, Triple Buffering
  4. 堆栈和堆得区别与垃圾回收
  5. Kilim实现浅析(一)
  6. centos 下编译 gcc
  7. Jq remove的使用
  8. Go语言 模糊搜索实验(一)
  9. 小程序图片在安卓上拉伸的问题导航返回首页
  10. django框架下celery+rabbitmq+flower完成异步任务