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

西安专业网站建设公司排名网页制作代码html制作一个网页

西安专业网站建设公司排名,网页制作代码html制作一个网页,网站制作的流程,二季域名做网站Matplotlib从入门到精通05-样式色彩秀芳华总结Matplotlib从入门到精通05-样式色彩秀芳华导入依赖一、matplotlib的绘图样式(style)1.matplotlib预先定义样式2.用户自定义stylesheet3.设置rcparams二、matplotlib的色彩设置(color)…

Matplotlib从入门到精通05-样式色彩秀芳华

    • 总结
    • Matplotlib从入门到精通05-样式色彩秀芳华
      • 导入依赖
      • 一、matplotlib的绘图样式(style)¶
        • 1.matplotlib预先定义样式¶
        • 2.用户自定义stylesheet¶
        • 3.设置rcparams¶
      • 二、matplotlib的色彩设置(color)¶
        • 1.RGB或RGBA¶
        • 2.HEX RGB 或 RGBA
        • 3.灰度色阶¶
        • 4.单字符基本颜色
        • 5.颜色名称
        • 6.使用colormap设置一组颜色¶

参考:
https://datawhalechina.github.io/fantastic-matplotlib/%E7%AC%AC%E4%B8%80%E5%9B%9E%EF%BC%9AMatplotlib%E5%88%9D%E7%9B%B8%E8%AF%86/index.html

https://matplotlib.org/stable/index.html

http://c.biancheng.net/matplotlib/data-visual.html

AI算法工程师手册

Task3:用极坐标系绘制玫瑰图&散点图和边际分布图的绘制

总结

本文主要是Matplotlib从入门到精通系列第5篇,本文介绍了Matplotlib的绘图样式和色彩设置,同时介绍了较好的参考文档置于博客前面,读者可以重点查看参考链接。本系列的目的是可以完整的完成Matplotlib从入门到精通。重点参考连接
在这里插入图片描述

Matplotlib从入门到精通05-样式色彩秀芳华

第五回详细介绍matplotlib中样式和颜色的使用,绘图样式和颜色是丰富可视化图表的重要手段,因此熟练掌握本章可以让可视化图表变得更美观,突出重点和凸显艺术性。

关于绘图样式,常见的有3种方法,分别是

修改预定义样式,自定义样式和rcparams。

关于颜色使用,本章介绍了

常见的5种表示单色颜色的基本方法,以及colormap多色显示的方法。

导入依赖

import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np

一、matplotlib的绘图样式(style)¶

在matplotlib中,要想设置绘制样式,最简单的方法是在绘制元素时单独设置样式。 但是有时候,当用户在做专题报告时,往往会希望保持整体风格的统一而不用对每张图一张张修改,因此matplotlib库还提供了四种批量修改全局样式的方式

1.matplotlib预先定义样式¶

matplotlib贴心地提供了许多内置的样式供用户使用,使用方法很简单,只需在python脚本的最开始输入想使用style的名称即可调用,尝试调用不同内置样式,比较区别

print(plt.style.available)plt.style.use('default')
plt.plot([1,2,3,4],[2,3,4,5]);plt.show()

[‘Solarize_Light2’, ‘_classic_test_patch’, ‘_mpl-gallery’, ‘_mpl-gallery-nogrid’, ‘bmh’, ‘classic’, ‘dark_background’, ‘fast’, ‘fivethirtyeight’, ‘ggplot’, ‘grayscale’, ‘seaborn-v0_8’, ‘seaborn-v0_8-bright’, ‘seaborn-v0_8-colorblind’, ‘seaborn-v0_8-dark’, ‘seaborn-v0_8-dark-palette’, ‘seaborn-v0_8-darkgrid’, ‘seaborn-v0_8-deep’, ‘seaborn-v0_8-muted’, ‘seaborn-v0_8-notebook’, ‘seaborn-v0_8-paper’, ‘seaborn-v0_8-pastel’, ‘seaborn-v0_8-poster’, ‘seaborn-v0_8-talk’, ‘seaborn-v0_8-ticks’, ‘seaborn-v0_8-white’, ‘seaborn-v0_8-whitegrid’, ‘tableau-colorblind10’]
在这里插入图片描述

plt.style.use('ggplot')
plt.plot([1,2,3,4],[2,3,4,5]);plt.show()

在这里插入图片描述

2.用户自定义stylesheet¶

在任意路径下创建一个后缀名为mplstyle的样式清单,编辑文件添加以下样式内容

axes.titlesize : 24
axes.labelsize : 20
lines.linewidth : 5
lines.markersize : 10
xtick.labelsize : 10
ytick.labelsize : 20

引用自定义stylesheet后观察图表变化。

plt.style.use('a.mplstyle')
plt.plot([1,2,3,4],[2,3,4,5])plt.show()

在这里插入图片描述

值得特别注意的是,matplotlib支持混合样式的引用,只需在引用时输入一个样式列表,若是几个样式中涉及到同一个参数,右边的样式表会覆盖左边的值。

plt.style.use(['dark_background', 'a.mplstyle'])
plt.plot([1,2,3,4],[2,3,4,5]);plt.show()

在这里插入图片描述

3.设置rcparams¶

我们还可以通过修改默认rc设置的方式改变样式,所有rc设置都保存在一个叫做 matplotlib.rcParams的变量中。
修改过后再绘图,可以看到绘图样式发生了变化。

plt.style.use('default') # 恢复到默认样式
mpl.rcParams['lines.linewidth'] = 2
mpl.rcParams['lines.linestyle'] = '--'
# mpl.rc('lines', linewidth=2, linestyle='-.') # 一次修改多个,与上面等价
plt.plot([1,2,3,4],[2,3,4,5])plt.show()

在这里插入图片描述

二、matplotlib的色彩设置(color)¶

在可视化中,如何选择合适的颜色和搭配组合也是需要仔细考虑的,色彩选择要能够反映出可视化图像的主旨。
从可视化编码的角度对颜色进行分析,可以将颜色分为色相、亮度和饱和度三个视觉通道。通常来说:

色相: 没有明显的顺序性、一般不用来表达数据量的高低,而是用来表达数据列的类别。
明度和饱和度: 在视觉上很容易区分出优先级的高低、被用作表达顺序或者表达数据量视觉通道。

具体关于色彩理论部分的知识,不属于本教程的重点,请参阅有关拓展材料学习。
学会这6个可视化配色基本技巧,还原数据本身的意义

如何为色盲色弱用户群体设计产品?

在matplotlib中,设置颜色有以下几种方式:

1.RGB或RGBA¶

plt.style.use('default')
# 颜色用[0,1]之间的浮点数表示,四个分量按顺序分别为(red, green, blue, alpha),其中alpha透明度可省略
plt.plot([1,2,3],[4,5,6],color=(0.1, 0.2, 0.5))
plt.plot([4,5,6],[1,2,3],color=(0.1, 0.2, 0.5, 0.5))plt.show()

在这里插入图片描述

2.HEX RGB 或 RGBA

# 用十六进制颜色码表示,同样最后两位表示透明度,可省略
plt.plot([1,2,3],[4,5,6],color='#0f0f0f')
plt.plot([4,5,6],[1,2,3],color='#0f0f0f80');plt.show()

在这里插入图片描述
RGB颜色和HEX颜色之间是可以一一对应的,以下网址提供了两种色彩表示方法的转换工具。
参考:
https://www.fontke.com/tool/rgb/0f0f0f/
https://www.colorhexa.com/

3.灰度色阶¶

# 当只有一个位于[0,1]的值时,表示灰度色阶
plt.plot([1,2,3],[4,5,6],color='0.5');plt.show()

在这里插入图片描述

4.单字符基本颜色

matplotlib有八个基本颜色,可以用单字符串来表示,分别是’b’, ‘g’, ‘r’, ‘c’, ‘m’, ‘y’, ‘k’, ‘w’,对应的是blue, green, red, cyan, magenta, yellow, black, and white的英文缩写

5.颜色名称

matplotlib提供了颜色对照表,可供查询颜色对应的名称
在这里插入图片描述
在这里插入图片描述

6.使用colormap设置一组颜色¶

有些图表支持使用colormap的方式配置一组颜色,从而在可视化中通过色彩的变化表达更多信息。

在matplotlib中,colormap共有五种类型:
顺序(Sequential)。通常使用单一色调,逐渐改变亮度和颜色渐渐增加,用于表示有顺序的信息

plot_color_gradients(‘Perceptually Uniform Sequential’,
[‘viridis’, ‘plasma’, ‘inferno’, ‘magma’, ‘cividis’])
plot_color_gradients(‘Sequential’,
[‘Greys’, ‘Purples’, ‘Blues’, ‘Greens’, ‘Oranges’, ‘Reds’,
‘YlOrBr’, ‘YlOrRd’, ‘OrRd’, ‘PuRd’, ‘RdPu’, ‘BuPu’,
‘GnBu’, ‘PuBu’, ‘YlGnBu’, ‘PuBuGn’, ‘BuGn’, ‘YlGn’])
plot_color_gradients(‘Sequential (2)’,
[‘binary’, ‘gist_yarg’, ‘gist_gray’, ‘gray’, ‘bone’,
‘pink’, ‘spring’, ‘summer’, ‘autumn’, ‘winter’, ‘cool’,
‘Wistia’, ‘hot’, ‘afmhot’, ‘gist_heat’, ‘copper’])

发散(Diverging)。改变两种不同颜色的亮度和饱和度,这些颜色在中间以不饱和的颜色相遇;当绘制的信息具有关键中间值(例如地形)或数据偏离零时,应使用此值。

plot_color_gradients(‘Diverging’,
[‘PiYG’, ‘PRGn’, ‘BrBG’, ‘PuOr’, ‘RdGy’, ‘RdBu’, ‘RdYlBu’,
‘RdYlGn’, ‘Spectral’, ‘coolwarm’, ‘bwr’, ‘seismic’])

循环(Cyclic)。改变两种不同颜色的亮度,在中间和开始/结束时以不饱和的颜色相遇。用于在端点处环绕的值,例如相角,风向或一天中的时间。

plot_color_gradients(‘Cyclic’, [‘twilight’, ‘twilight_shifted’, ‘hsv’])

定性(Qualitative)。常是杂色,用来表示没有排序或关系的信息。

plot_color_gradients(‘Qualitative’,
[‘Pastel1’, ‘Pastel2’, ‘Paired’, ‘Accent’, ‘Dark2’,
‘Set1’, ‘Set2’, ‘Set3’, ‘tab10’, ‘tab20’, ‘tab20b’,
‘tab20c’])

杂色(Miscellaneous)。一些在特定场景使用的杂色组合,如彩虹,海洋,地形等。

plot_color_gradients(‘Miscellaneous’,
[‘flag’, ‘prism’, ‘ocean’, ‘gist_earth’, ‘terrain’,
‘gist_stern’, ‘gnuplot’, ‘gnuplot2’, ‘CMRmap’,
‘cubehelix’, ‘brg’, ‘gist_rainbow’, ‘rainbow’, ‘jet’,
‘turbo’, ‘nipy_spectral’, ‘gist_ncar’])
plt.show()

具体见:
https://matplotlib.org/stable/tutorials/colors/colormaps.html

完整代码:

import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
# from colorspacious import cspace_convertercmaps = {}gradient = np.linspace(0, 1, 256)
gradient = np.vstack((gradient, gradient))def plot_color_gradients(category, cmap_list):# Create figure and adjust figure height to number of colormapsnrows = len(cmap_list)figh = 0.35 + 0.15 + (nrows + (nrows - 1) * 0.1) * 0.22fig, axs = plt.subplots(nrows=nrows + 1, figsize=(6.4, figh))fig.subplots_adjust(top=1 - 0.35 / figh, bottom=0.15 / figh,left=0.2, right=0.99)axs[0].set_title(f'{category} colormaps', fontsize=14)for ax, name in zip(axs, cmap_list):ax.imshow(gradient, aspect='auto', cmap=mpl.colormaps[name])ax.text(-0.01, 0.5, name, va='center', ha='right', fontsize=10,transform=ax.transAxes)# Turn off *all* ticks & spines, not just the ones with colormaps.for ax in axs:ax.set_axis_off()# Save colormap list for later.cmaps[category] = cmap_listplot_color_gradients('Perceptually Uniform Sequential',['viridis', 'plasma', 'inferno', 'magma', 'cividis'])plt.show()

在这里插入图片描述


文章转载自:
http://gibson.wjrq.cn
http://aftermath.wjrq.cn
http://flag.wjrq.cn
http://samar.wjrq.cn
http://malformed.wjrq.cn
http://vacua.wjrq.cn
http://outwards.wjrq.cn
http://cifs.wjrq.cn
http://exabyte.wjrq.cn
http://kayf.wjrq.cn
http://crystalloid.wjrq.cn
http://woodbind.wjrq.cn
http://impiously.wjrq.cn
http://cardiomegaly.wjrq.cn
http://ultranationalism.wjrq.cn
http://sibu.wjrq.cn
http://accomplishment.wjrq.cn
http://proficiency.wjrq.cn
http://fawny.wjrq.cn
http://hotheaded.wjrq.cn
http://caviler.wjrq.cn
http://xanthoproteic.wjrq.cn
http://airbed.wjrq.cn
http://shingon.wjrq.cn
http://debilitated.wjrq.cn
http://basting.wjrq.cn
http://perinde.wjrq.cn
http://elaterin.wjrq.cn
http://lignosulphonate.wjrq.cn
http://demophil.wjrq.cn
http://vying.wjrq.cn
http://adscription.wjrq.cn
http://tactics.wjrq.cn
http://tugboat.wjrq.cn
http://lateen.wjrq.cn
http://passionless.wjrq.cn
http://preference.wjrq.cn
http://cismontane.wjrq.cn
http://mining.wjrq.cn
http://shawmist.wjrq.cn
http://snug.wjrq.cn
http://dimuon.wjrq.cn
http://crusher.wjrq.cn
http://cloisterer.wjrq.cn
http://indescribably.wjrq.cn
http://cetologist.wjrq.cn
http://bathsheba.wjrq.cn
http://hypopharynx.wjrq.cn
http://citizenry.wjrq.cn
http://worcestershire.wjrq.cn
http://crusade.wjrq.cn
http://cytotrophoblast.wjrq.cn
http://emplane.wjrq.cn
http://truncal.wjrq.cn
http://methemoglobin.wjrq.cn
http://divers.wjrq.cn
http://headforemost.wjrq.cn
http://tetrawickmanite.wjrq.cn
http://astrid.wjrq.cn
http://angelhood.wjrq.cn
http://viropexis.wjrq.cn
http://invest.wjrq.cn
http://gangload.wjrq.cn
http://trieteric.wjrq.cn
http://personhood.wjrq.cn
http://tabanid.wjrq.cn
http://ccm.wjrq.cn
http://bondsman.wjrq.cn
http://crane.wjrq.cn
http://puzzlist.wjrq.cn
http://embacle.wjrq.cn
http://registration.wjrq.cn
http://outstay.wjrq.cn
http://realign.wjrq.cn
http://solicitorship.wjrq.cn
http://sanguiferous.wjrq.cn
http://pteridology.wjrq.cn
http://unadornment.wjrq.cn
http://imitated.wjrq.cn
http://geometer.wjrq.cn
http://committee.wjrq.cn
http://trisaccharide.wjrq.cn
http://goshen.wjrq.cn
http://digital.wjrq.cn
http://skimeister.wjrq.cn
http://funnelled.wjrq.cn
http://everglade.wjrq.cn
http://harmattan.wjrq.cn
http://thickening.wjrq.cn
http://xenogeneic.wjrq.cn
http://semisecret.wjrq.cn
http://churn.wjrq.cn
http://metonymical.wjrq.cn
http://botswana.wjrq.cn
http://wobbly.wjrq.cn
http://korfball.wjrq.cn
http://cissoidal.wjrq.cn
http://unpoetical.wjrq.cn
http://polyplane.wjrq.cn
http://somnus.wjrq.cn
http://www.hrbkazy.com/news/78688.html

相关文章:

  • 做电影网站侵权吗中国最好的网络营销公司
  • 信用中国网站是哪个部委支持建设的培训机构优化
  • 做毕业设计一个网站的数据来源谷歌推广公司
  • 数据查询插件 wordpress泰州seo
  • 衢州网站设计方案链接生成器在线制作
  • 宁德时代网站哪个公司做的seo搜索引擎优化的内容
  • 适合公司建设的网站电商运营的基本内容
  • 做视频在哪个网站找素材懂得网站推广
  • 网络推广培训心得线下课程seo
  • 茂名网站建设方案推广深圳百度国际大厦
  • 基金会网站建设方案淘宝引流推广平台
  • python做网站实战搜索引擎优化seo名词解释
  • 龙华网页设计公司网站百度渠道开户哪里找
  • 做网站推广方法有哪些百度seo优化
  • 怎样在手机上制作网站第一接单网app地推和拉新
  • 深圳知名网站建设供应百度免费官网入口
  • 上海公司推荐慈溪seo
  • 广州天与地网站建设seo网络优化师招聘
  • 外围网站怎么做百度快速排名化
  • 个人音乐网站建设友情链接大全
  • 国内做批发的网站新媒体运营培训课程
  • 了解网站开发的一般过程seo排名外包
  • 网至普的营销型网站布局模板建站公司
  • 辽宁省住房和城乡建设网站百度关键词在线优化
  • 香港主机做福彩网站宁波seo怎么推广
  • 有和wind一样做用网站网站页面seo
  • 做网站需要要多少钱竞价推广是什么工作
  • 杭州集团网站建设方案昆明网站开发推广公司
  • 网站一个人可以做吗百度搜图入口
  • 网站的结构是什么样的软文广告100字