准备工作:

心形曲线的计算公式:(x^2+y^2-1)^3+x^2*y^3=0

依赖库:numpy 和 matplotlib

pip3 install numpy
pip3 install matplotlib

No module named ‘matplotlib‘ 解决办法
No module named ‘numpy‘的解决办法

源码:

import numpy as npimport matplotlib.pyplot as pltx_coords = np.linspace(- 100, 100, 500)y_coords = np.linspace(- 100, 100, 500)points = []for y in y_coords:for x in x_coords:if ((x * 0.03) ** 2 + (y * 0.03) ** 2 - 1) ** 3 - (x * 0.03) ** 2 * (y * 0.03) ** 3 <= 0:points.append({"x": x, "y": y})heart_x = list(map(lambda point: point["x"], points))heart_y = list(map(lambda point: point["y"], points))plt.scatter(heart_x, heart_y, s=10, alpha=0.5)plt.show()

效果图:

爱心基本款-初心:

上面代码运行后:

高级爱心定制款

给爱心填充不同的颜色,只需在上面代码的 “scatter函数” 中指定 “cmap参数” 即可,如下:

plt.scatter(heart_x, heart_y, s=10, alpha=0.5, c=range(len(heart_x)), cmap=<cmap>)

通过改变"cmap"这个参数,就可以定制不同款色的高级爱心啦!
例如:

plt.scatter(heart_x, heart_y, s=10, alpha=0.5, c=range(len(heart_x)), cmap="autumn")

<cmap = “autumn”> 橙色-热情洋溢的她

<cmap = “spring”> 青春-充满朝气的她

<cmap = “rainbow”> 彩虹-充满绚丽幻想的她

<cmap = “cool”> 紫色-优雅宁静的她

<cmap = “magma”> 晚霞-醇厚脱俗的她

<cmap = “Reds”> 炽热-热烈奔放的她

<cmap = “viridis”> 翡翠-平静柔和的她

<cmap = “gist_rainbow”> 五彩缤纷-多姿多彩的她

Much More:总有一款适合你

values: Accent, Accent_r, Blues, Blues_r, BrBG, BrBG_r, BuGn, BuGn_r, BuPu, BuPu_r, CMRmap, CMRmap_r, Dark2, Dark2_r, GnBu, GnBu_r, Greens, Greens_r, Greys, Greys_r, OrRd, OrRd_r, Oranges, Oranges_r, PRGn, PRGn_r, Paired, Paired_r, Pastel1, Pastel1_r, Pastel2, Pastel2_r, PiYG, PiYG_r, PuBu, PuBuGn, PuBuGn_r, PuBu_r, PuOr, PuOr_r, PuRd, PuRd_r, Purples, Purples_r, RdBu, RdBu_r, RdGy, RdGy_r, RdPu, RdPu_r, RdYlBu, RdYlBu_r, RdYlGn, RdYlGn_r, Reds, Reds_r, Set1, Set1_r, Set2, Set2_r, Set3, Set3_r, Spectral, Spectral_r, Vega10, Vega10_r, Vega20, Vega20_r, Vega20b, Vega20b_r, Vega20c, Vega20c_r, Wistia, Wistia_r, YlGn, YlGnBu, YlGnBu_r, YlGn_r, YlOrBr, YlOrBr_r, YlOrRd, YlOrRd_r, afmhot, afmhot_r, autumn, autumn_r, binary, binary_r, bone, bone_r, brg, brg_r, bwr, bwr_r, cool, cool_r, coolwarm, coolwarm_r, copper, copper_r, cubehelix, cubehelix_r, flag, flag_r, gist_earth, gist_earth_r, gist_gray, gist_gray_r, gist_heat, gist_heat_r, gist_ncar, gist_ncar_r, gist_rainbow, gist_rainbow_r, gist_stern, gist_stern_r, gist_yarg, gist_yarg_r, gnuplot, gnuplot2, gnuplot2_r, gnuplot_r, gray, gray_r, hot, hot_r, hsv, hsv_r, inferno, inferno_r, jet, jet_r, magma, magma_r, nipy_spectral, nipy_spectral_r, ocean, ocean_r, pink, pink_r, plasma, plasma_r, prism, prism_r, rainbow, rainbow_r, seismic, seismic_r, spectral, spectral_r, spring, spring_r, summer, summer_r, tab10, tab10_r, tab20, tab20_r, tab20b, tab20b_r, tab20c, tab20c_r, terrain, terrain_r, viridis, viridis_r, winter, winter_r

python之定制多种彩虹色爱心相关推荐

  1. python画图代码彩虹-用python画一颗彩虹色爱心送给女朋友!!!

    1.准备工作: 代码中用到numpy和matplotlib,需要先安装这两个库 pip3 install numpypip3 install matplotlib 会用到的数学公式:(x^2+y^2- ...

  2. python画彩虹爱心_用python画一颗彩虹色爱心送给女朋友!!!

    1.准备工作: 代码中用到numpy和matplotlib,需要先安装这两个库 pip3 install numpypip3 install matplotlib 会用到的数学公式:(x^2+y^2- ...

  3. 用python画名字组成的爱心_520用Python画一颗特别的爱心送给她

    原标题:520用Python画一颗特别的爱心送给她 来源: Python与数据分析(ID:PythonML,已获授权) 520,大家有没有和心爱的女生在一起呢? 今天我们来用Python画一颗特别的爱 ...

  4. python画动态爱心-使用Python画出小人发射爱心的代码

    我就废话不多说了,直接上代码吧! #2.14 from turtle import * from time import sleep def go_to(x, y): up() goto(x, y) ...

  5. python编程爱心-使用Python画出小人发射爱心的代码

    我就废话不多说了,直接上代码吧! #2.14 from turtle import * from time import sleep def go_to(x, y): up() goto(x, y) ...

  6. python送心小人_使用Python画出小人发射爱心的代码

    我就废话不多说了,直接上代码吧! #2.14 from turtle import * from time import sleep def go_to(x, y): up() goto(x, y) ...

  7. python小人画爱心_使用Python画出小人发射爱心的代码

    我就废话不多说了,直接上代码吧! #2.14 from turtle import * from time import sleep def go_to(x, y): up() goto(x, y) ...

  8. Python的turtle模块画爱心箭(附源码)

    Python的turtle模块画爱心箭源码 import turtle as t t.hideturtle() t.speed(100) def f(a,b):#画箭,a,b为箭尖坐标t.penup( ...

  9. python读二进制格点雷达基数据_radar: 基于python pycinrad 以及多种类库 编写基于java 的雷达基数据统一格式读取...

    radar-core 介绍 基于python pycinrad 以及多种类库 编写基于java 的雷达基数据统一格式读取 包括读取分层ppi.插值到等经纬度的网格化ppi以及 cappi.vcs等基本 ...

最新文章

  1. 概率统计概念复习:MAPMLE
  2. mysql delete in 结果集_MySQL从删库到跑路(2)SQL语句示例
  3. 教大家白嫖图床,有的小伙伴跟我说图床不好整,太麻烦
  4. 吴恩达斯坦福大学机器学习 CS229 课程学习笔记(二)
  5. Nginx 附录C 模块编译,调试与测试
  6. 一行Python代码计算两点间曼哈顿距离
  7. 程序员发展职业规划_大厂程序员总结:程序员30岁前,该如何规划自己的职业发展?...
  8. 树莓派进阶之路 (023) - Windows下用串行连接控制树莓派(转)
  9. 20145228《网络对抗》 后门原理与实践
  10. html怎么制作小黄人,教你如何自己动手制作小黄人模型攻略
  11. 空洞卷积的使用增大感受野
  12. 移动统计工具Flurry
  13. PyQt5,一个好的qt教程。
  14. MYSQL主从部署(Censo:6)
  15. unity3D地形编辑器—Terrain
  16. 苹果不显示订阅服务器,苹果xr找不到订阅管理?苹果xr找不到订阅管理解决办法...
  17. python画长尾图_t-SNE完整笔记 (附Python代码)
  18. Redis集群搭建(转自一菲聪天的“Windows下搭建Redis集群”)
  19. 运用广告监测系统,上海发布十二起违法广告典型案例-十目监测
  20. 中国将自主建造宇宙空间站

热门文章

  1. Azure China (5) 管理Azure China Powershell
  2. 删除数组中的指定元素 | JavaScript
  3. 前端05.js入门之BOM对象与DOM对象。
  4. 扩展Python模块系列(四)----引用计数问题的处理
  5. JVM性能优化, Part 5:Java的伸缩性
  6. Simulink Memory vs Unit Delay
  7. 深入研究java.lang.Runtime类,Process类
  8. ATA/SATA/SCSI/SAS/FC总线简介
  9. 关于GCD执行任务的理解
  10. 高速理解掌握node.js 字符编码,确码过程 以及base64编解码原理