当前位置: 首页 > news >正文

网站开发与系统开发室内设计师工作室

网站开发与系统开发,室内设计师工作室,网站后期维护很难吗,新农村基础设施建设网站在前述学习过程中#xff0c;我们已经通过官网学习了如何绘制渐变的柱状图及其背景。 掌握一门技能的最佳检验方式就是通过实战#xff0c;因此#xff0c;本文尝试做一些渐变设计。 前述学习记录可查看链接#xff1a; Python画图|渐变背景-CSDN博客 【1】柱状图渐变 …在前述学习过程中我们已经通过官网学习了如何绘制渐变的柱状图及其背景。 掌握一门技能的最佳检验方式就是通过实战因此本文尝试做一些渐变设计。 前述学习记录可查看链接 Python画图|渐变背景-CSDN博客 【1】柱状图渐变 在上一篇文章中由于代码太长对单个函数的解读不够详细在本文中可以详细展开。 首先将背景渐变的代码改为注释原因为 【a】所有渐变都使用了gradient_image()函数 【b】gradient_bar()函数通过调用gradient_image()函数画出了渐变的柱状图 【c】调用gradient_image()函数单独定义了背景渐变。 因此在不对代码进行修改的前提下最快速的更改就是把背景渐变的代码消除 # background image #gradient_image(ax, direction1, extent(0, 1, 0, 1), transformax.transAxes,#cmapplt.cm.RdYlGn, cmap_range(0.2, 0.9), alpha0.5) #调用了子函数 此时的输出结果为 图1 由图1可见坐标轴区域内部已经改为纯色仅柱状图变成渐变颜色。 然后尝试修改颜色将柱状图的渐变色改为cmap由plt.cm.Blues_r改为plt.cm.Blues此时的输出结果为 图2 对比图1和图2可见渐变的方向进行了交换。 【2】渐变代码解读 经过追溯 gradient_bar()函数和gradient_image()函数的构造和使用基本上都参考了ax.imshow()函数。 【2.1】ax.imshow()函数 因在实施渐变以前有必要先学习ax.imshow()函数 https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.imshow.html#matplotlib.axes.Axes.imshow Axes.imshow(X, cmapNone, normNone, *, aspectNone, interpolationNone, alphaNone, vminNone, vmaxNone, originNone, extentNone, interpolation_stageNone, filternormTrue, filterrad4.0, resampleNone, urlNone, dataNone, **kwargs) ax.imshow()包含参数意义如下 X画图数据依据 cmap颜色参数 norm标准化工具将cmap数据缩放到(0,1)范围 aspect设定坐标轴的长宽比 interpolation插值设置 alpha透明度设置 origin设定数组的起点在左下角还是左上角 extent边界框 interpolation_stage插值范围 filternorm图像粒度调整 filterrad与差值先关 其余如resample、url、dataNone和**kwargs不常用暂无需关注。 【2.2】gradient_bar()函数 基于此我们尝试解读下述代码 def gradient_bar(ax, x, y, width0.5, bottom0): #自定义函数for left, top in zip(x, y):right left width #右边等于左边加宽度这是要逐个排列的意思gradient_image(ax, extent(left, right, bottom, top),cmapplt.cm.Blues##, cmap_range(0.2, 0.9) 第一行 def gradient_bar(ax, x, y, width0.5, bottom0): #自定义函数 其中的ax,x,y均为外部输入变量 width0.5, bottom0为内部已经完成定义的变量。 for函数对x和y组成的组合数组进行取值。 right是内部变量leftwidth代表着柱状图不断右移。 gradient_image()函数在此处被直接调用调用的时候只需要外部输入ax其余参数如extent、cmap和cmap_range都已经提前完成了赋值。 【2.3】gradient_image()函数 基于前述分析我们尝试解读下述代码 # background image gradient_image(ax, direction1, extent(0, 1, 0, 1), transformax.transAxes,cmapplt.cm.RdYlGn, cmap_range(0.2, 0.9), alpha0.5) #调用了子函数 这里是对gradient_image()函数的直接调用几乎所有参数都已经解读过稍有变化的是里面多了一个transform参数这里的transformax.transAxes就是把ax值转化为Axes值 顺直坐标轴画直方图的意思。 【3】渐变调控 根据前述分析已经知晓柱状图渐变和背景渐变可以分别设置因此此处尝试消除柱状图渐变然后恢复背景渐变。 【3.1】柱状图渐变 消除柱状图渐变最快的方式是将cmap_range的赋值改成一致的即可 def gradient_bar(ax, x, y, width0.5, bottom0): #自定义函数for left, top in zip(x, y):right left width #右边等于左边加宽度这是要逐个排列的意思gradient_image(ax, extent(left, right, bottom, top),cmapplt.cm.Blues, cmap_range(0.8, 0.8)) 此时的输出图像为 图3 【3.2】背景渐变 消除背景图渐变最快的方式也是将cmap_range的赋值改成一致的即可 # background image gradient_image(ax, direction1, extent(0,1,0, 1), transformax.transAxes,cmapplt.cm.RdYlGn, cmap_range(0.9, 0.9), alpha0.5) #调用了子函数 此时的输出图像为 图4 至此所有渐变已经消除。 至此的完整代码为 import matplotlib.pyplot as plt # 引入matplotlib模块画图 import numpy as np # 引入numpy模块做数学计算np.random.seed(19680801) #定义随机数种子def gradient_image(ax, direction0.3, cmap_range(0, 1), **kwargs): #自定义函数Draw a gradient image based on a colormap.Parameters----------ax : AxesThe Axes to draw on.direction : floatThe direction of the gradient. This is a number inrange 0 (vertical) to 1 (horizontal).cmap_range : float, floatThe fraction (cmin, cmax) of the colormap that should beused for the gradient, where the complete colormap is (0, 1).**kwargsOther parameters are passed on to .Axes.imshow().In particular, *cmap*, *extent*, and *transform* may be useful.phi direction * np.pi / 2 #定义因变量从np.pi可以看出这是一个角度变量v np.array([np.cos(phi), np.sin(phi)]) #定义数组包括正弦值和余弦值X np.array([[v [1, 0], v [1, 1]],[v [0, 0], v [0, 1]]]) #这里的是矩阵乘法a, b cmap_range #定义变量a和bX a (b - a) / X.max() * X #定义变量Xim ax.imshow(X, interpolationbicubic, clim(0, 1),aspectauto, **kwargs) #定义变量imreturn im #返回imdef gradient_bar(ax, x, y, width0.5, bottom0): #自定义函数for left, top in zip(x, y):right left width #右边等于左边加宽度这是要逐个排列的意思gradient_image(ax, extent(left, right, bottom, top),cmapplt.cm.Blues, cmap_range(0.8, 0.8))fig, ax plt.subplots() ax.set(xlim(0, 10), ylim(0, 1))# background image gradient_image(ax, direction1, extent(0,1,0, 1), transformax.transAxes,cmapplt.cm.RdYlGn, cmap_range(0.9, 0.9), alpha0.5) #调用了子函数N 10 #定义常量10 x np.arange(N) 0.15 #使用随机变量参与运算制造变量x y np.random.rand(N) #定义随机矩阵 gradient_bar(ax, x, y, width0.7) #画随机柱状图 plt.show() #输出图形 【4】坐标轴外背景颜色设置 在前述学习过程中已经讨论了坐标轴以外的颜色设置详见下述链接 python画图|图像背景颜色设置-CSDN博客 此处的渐变仅仅涉及坐标轴内部区域和柱状图本身基于此尝试设置坐标轴外部的颜色修改画图代码为 fig, ax plt.subplots(facecolor(0.6, 0.5,0.9))此时的输出结果为 图5 由图5可见外部背景、坐标轴内都有了颜色。 此时的完整代码为 import matplotlib.pyplot as plt # 引入matplotlib模块画图 import numpy as np # 引入numpy模块做数学计算np.random.seed(19680801) #定义随机数种子def gradient_image(ax, direction0.3, cmap_range(0, 1), **kwargs): #自定义函数Draw a gradient image based on a colormap.Parameters----------ax : AxesThe Axes to draw on.direction : floatThe direction of the gradient. This is a number inrange 0 (vertical) to 1 (horizontal).cmap_range : float, floatThe fraction (cmin, cmax) of the colormap that should beused for the gradient, where the complete colormap is (0, 1).**kwargsOther parameters are passed on to .Axes.imshow().In particular, *cmap*, *extent*, and *transform* may be useful.phi direction * np.pi / 2 #定义因变量从np.pi可以看出这是一个角度变量v np.array([np.cos(phi), np.sin(phi)]) #定义数组包括正弦值和余弦值X np.array([[v [1, 0], v [1, 1]],[v [0, 0], v [0, 1]]]) #这里的是矩阵乘法a, b cmap_range #定义变量a和bX a (b - a) / X.max() * X #定义变量Xim ax.imshow(X, interpolationbicubic, clim(0, 1),aspectauto, **kwargs) #定义变量imreturn im #返回imdef gradient_bar(ax, x, y, width0.5, bottom0): #自定义函数for left, top in zip(x, y):right left width #右边等于左边加宽度这是要逐个排列的意思gradient_image(ax, extent(left, right, bottom, top),cmapplt.cm.Blues, cmap_range(0.8, 0.8))fig, ax plt.subplots(facecolor(0.6, 0.5,0.9)) #设置坐标轴外区域颜色 ax.set(xlim(0, 10), ylim(0, 1))# background image gradient_image(ax, direction1, extent(0,1,0, 1), transformax.transAxes,cmapplt.cm.RdYlGn, cmap_range(0.9, 0.9), alpha0.5) #调用了子函数N 10 #定义常量10 x np.arange(N) 0.15 #使用随机变量参与运算制造变量x y np.random.rand(N) #定义随机矩阵 gradient_bar(ax, x, y, width0.7) #画随机柱状图 plt.show() #输出图形 【5】自主渐变设置 在前述学习的基础上给所有区域山上色并对坐标轴内部区域进行渐变设置并设置图名为“Gradient Color”。 完整代码为 import matplotlib.pyplot as plt # 引入matplotlib模块画图 import numpy as np # 引入numpy模块做数学计算np.random.seed(19680801) #定义随机数种子def gradient_image(ax, direction0.3, cmap_range(0, 1), **kwargs): #自定义函数Draw a gradient image based on a colormap.Parameters----------ax : AxesThe Axes to draw on.direction : floatThe direction of the gradient. This is a number inrange 0 (vertical) to 1 (horizontal).cmap_range : float, floatThe fraction (cmin, cmax) of the colormap that should beused for the gradient, where the complete colormap is (0, 1).**kwargsOther parameters are passed on to .Axes.imshow().In particular, *cmap*, *extent*, and *transform* may be useful.phi direction * np.pi / 2 #定义因变量从np.pi可以看出这是一个角度变量v np.array([np.cos(phi), np.sin(phi)]) #定义数组包括正弦值和余弦值X np.array([[v [1, 0], v [1, 1]],[v [0, 0], v [0, 1]]]) #这里的是矩阵乘法a, b cmap_range #定义变量a和bX a (b - a) / X.max() * X #定义变量Xim ax.imshow(X, interpolationbicubic, clim(0, 1),aspectauto, **kwargs) #定义变量imreturn im #返回imdef gradient_bar(ax, x, y, width0.5, bottom0): #自定义函数for left, top in zip(x, y):right left width #右边等于左边加宽度这是要逐个排列的意思gradient_image(ax, extent(left, right, bottom, top),cmapplt.cm.Blues, cmap_range(0.2, 0.8))fig, ax plt.subplots(facecolor(0.6, 0.5,0.9)) #设置坐标轴外区域颜色 ax.set(xlim(0, 10), ylim(0, 1))# background image gradient_image(ax, direction1, extent(0,1,0, 1), transformax.transAxes,cmapplt.cm.RdYlGn, cmap_range(0.1, 0.9), alpha0.5) #调用了子函数N 10 #定义常量10 x np.arange(N) 0.15 #使用随机变量参与运算制造变量x y np.random.rand(N) #定义随机矩阵 gradient_bar(ax, x, y, width0.7) #画随机柱状图 ax.set_title(Gradient Color) #设置图名 plt.show() #输出图形 输出图形为 图6 由图6可见坐标轴内部的柱状图和背景颜色均渐变坐标轴外的区域则是纯色。 【6】总结 学习了柱状图、坐标轴区域内部背景颜色的渐变设计以及为坐标轴外部区域增添颜色。
http://www.hkea.cn/news/14464488/

相关文章:

  • 中国能建设计公司网站专门代写平台
  • 常用的网站开发语言平面设计和网页设计哪个好
  • 施工程找工程做哪个网站好深圳网站制作建设服务公司
  • 外贸网站模板 外贸网站制作公共资源交易中心有实权吗
  • 做旅游网站用什么颜色永兴网站开发
  • 关于网站建设外文文献柘城网站建设
  • 中国站长网入口做一套网站开发多少钱
  • 安溪网站建设长春市长春网站建设
  • 柳州网站建设数公式大全学历提升销售好做吗
  • 宁波网站建设开发服务wordpress插件pdf
  • 公司网站建设的作用与意义自动化设备东莞网站建设
  • asp做静态网站芜湖网站开发公司
  • 哪个商城网站建设好建设asp网站视频教程
  • 深圳便宜的网站建设百度官网平台
  • 重庆北碚网站建设深圳做app网站公司
  • 企业数据查询网站海曙网站制作
  • 抖音小程序在哪里杭州新站整站seo
  • 做图表好用网站或软件google和百度等相关网站的广告词
  • 网站都要交域名费么公司网址一般是什么
  • 用asp.net做购物网站手机系统网站
  • wordpress用网站测速廊坊seo霸屏
  • 吉林省软环境建设网站三端互通传奇发布网
  • 网站推广存在的问题温州网站的优化
  • 网站keyword如何排列网站建设有什么工作
  • 微信公众号 手机网站七初SEO网站建设
  • 食品行业网站建设网站策划技巧
  • 网站怎么做优化推广seo的实现方式
  • 怎样开网站免费网站大全下载
  • 常州网站建设优化h5营销
  • 做h5那个网站好深圳大型商城网站建设