使用python绘制各种颜色的3d玫瑰花送给女朋友

效果

快过年了,给你的电子女友送上一朵赛博玫瑰花吧!

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

代码与颜色参数

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

fig = plt.figure()
ax = fig.add_axes(Axes3D(fig))
[x, t] = np.meshgrid(np.array(range(25)) / 24.0, np.arange(0, 575.5, 0.5) / 575 * 30 * np.pi - 4 * np.pi)
p = (np.pi / 2) * np.exp(-t / (8 * np.pi))
change = np.sin(20 * t) / 50
u = 1 - (1 - np.mod(3.3 * t, 2 * np.pi) / np.pi) ** 4 / 2 + change
y = 2 * (x ** 2 - x) ** 2 * np.sin(p)
r = u * (x * np.sin(p) + y * np.cos(p)) * 1.5
h = u * (x * np.cos(p) - y * np.sin(p))
c = plt.get_cmap('Accent')  # 修改颜色
surf = ax.plot_surface(r * np.cos(t), r * np.sin(t), h, rstride=1, cstride=1,
                       cmap=c, linewidth=0, antialiased=True)
plt.show()

修改颜色语句 c = plt.get_cmap('Accent')
修改参数即可修改颜色,可选颜色参数如下:
AccentAccent_rBluesBlues_rBrBGBrBG_r
BuGnBuGn_rBuPuBuPu_rCMRmapCMRmap_r
Dark2Dark2_rGnBuGnBu_rGreensGreens_r
GreysGreys_rOrRdOrRd_rOrangesOranges_r
PRGnPRGn_rPairedPaired_rPastel1Pastel1_r
Pastel2Pastel2_rPiYGPiYG_rPuBuPuBuGn
PuBuGn_rPuBu_rPuOrPuOr_rPuRdPuRd_r
PurplesPurples_rRdBuRdBu_rRdGyRdGy_r
RdPuRdPu_rRdYlBuRdYlBu_rRdYlGnRdYlGn_r
RedsReds_rSet1Set1_rSet2Set2_r
Set3Set3_rSpectralSpectral_rWistiaWistia_r
YlGnYlGnBuYlGnBu_rYlGn_rYlOrBrYlOrBr_r
YlOrRdYlOrRd_rafmhotafmhot_rautumnautumn_r
binarybinary_rbonebone_rbrgbrg_r
bwrbwr_rcividiscividis_rcoolcool_r
coolwarmcoolwarm_rcoppercopper_rcubehelixcubehelix_r
flagflag_rgist_earthgist_earth_rgist_graygist_gray_r
gist_heatgist_heat_rgist_ncargist_ncar_rgist_rainbowgist_rainbow_r
gist_sterngist_stern_rgist_yarggist_yarg_rgnuplotgnuplot2
gnuplot2_rgnuplot_rgraygray_rhothot_r
hsvhsv_rinfernoinferno_rjetjet_r
magmamagma_rnipy_spectralnipy_spectral_roceanocean_r
pinkpink_rplasmaplasma_rprismprism_r
rainbowrainbow_rseismicseismic_rspringspring_r
summersummer_rtab10tab10_rtab20tab20_r
tab20btab20b_rtab20ctab20c_rterrainterrain_r
turboturbo_rtwilighttwilight_rtwilight_shiftedtwilight_shifted_r
viridisviridis_rwinterwinter_r
Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐