首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >100+SCI科研绘图系列教程(R和python)

100+SCI科研绘图系列教程(R和python)

原创
作者头像
生信学习者
修改2024-10-23 07:51:33
修改2024-10-23 07:51:33
66500
代码可运行
举报
运行总次数:0
代码可运行
  1. 科研绘图系列:箱线图加百分比点图展示组间差异-CSDN博客
  2. 科研绘图系列:箱线图加蜜蜂图展示组间数据分布-CSDN博客
  3. 科研绘图系列:小提琴图和双侧小提琴图展示组间差异-CSDN博客
  4. 科研绘图系列:组间差异的STAMP图的ggplot2实现-CSDN博客
  5. 科研绘图系列:组间差异误差棒展示-CSDN博客
  6. 科研绘图系列:甜圈圈donut图展示比例-CSDN博客
  7. 科研绘图系列:多层圆图展示不同分组的比例-CSDN博客
  8. 科研绘图系列:带有点的柱状图-CSDN博客
  9. 科研绘图系列:双侧条形图或柱状图-CSDN博客
  10. 科研绘图系列:箱线图(分组数目和离群点现实)-CSDN博客
  11. 科研绘图系列:主成分散点图的组间边界标记-CSDN博客
  12. 科研绘图系列:带有卡方检验的分组堆积图-CSDN博客
  13. 科研绘图系列:雨云图展示更多数据分布信息-CSDN博客
  14. 科研绘图系列:展示病人临床信息的swimming plot
  15. 科研绘图系列:桑基图展示数据层流动-CSDN博客
  16. 科研绘图系列:绘制带有显著性标记的误差棒图-CSDN博客
  17. 科研绘图系列:ggplot2绘制双y轴图-CSDN博客
  18. 科研绘图系列:Venn图进阶版本-CSDN博客
  19. 科研绘图系列:不同分页界面分组添加显著性标记符号-CSDN博客
  20. 科研绘图系列:剂量反应曲线图-CSDN博客
  21. 科研绘图系列:实验组间点图比较-CSDN博客
  22. 科研绘图系列:实验组间点图比较-CSDN博客
  23. 科研绘图系列:可直接发表的柱状图-CSDN博客
  24. 科研绘图系列:可发表的Y轴截断图-CSDN博客
  25. 科研绘图系列:可发表的prism点图-CSDN博客
  26. 科研绘图系列:单细胞常用的降纬图-CSDN博客
  27. 科研绘图系列:生存分析森林图-CSDN博客
  28. 科研绘图系列:可发表的热图-CSDN博客
  29. 科研绘图系列:给柱状图添加网格-CSDN博客
  30. 科研绘图系列:微生物相对丰度或富集热图可视化-CSDN博客
  31. 科研绘图系列:科研绘图之生存KM曲线图-CSDN博客
  32. 科研绘图系列:R语言STAMP图(STAMP Plot)
  33. 科研绘图系列:R语言蜜蜂图(Beeswarm Plot)
  34. 科研绘图系列:R语言小提琴图(Violin Plot)
  35. 科研绘图系列:R语言点数图(dot plot)
  36. 科研绘图系列:R语言箱线图(boxplot)-CSDN博客
  37. 科研绘图系列:R语言双侧条形图(bar Plot)
  38. 科研绘图系列:R语言实验结果组图(linechart + barplot)
  39. 科研绘图系列:R语言两组数据散点分布图(scatter plot)
  40. 科研绘图系列:R语言径向柱状图(Radial Bar Chart)
  41. 科研绘图系列:R语言分组柱状图一(Grouped Bar Chart)
  42. 科研绘图系列:R语言分组柱状图二(Grouped Bar Chart)
  43. 科研绘图系列:R语言分组柱状图三(Grouped Bar Chart)
  44. 科研绘图系列:R语言分组柱状图四(Grouped Bar Chart)
  45. 科研绘图系列:R语言多个精美图形组图-CSDN博客
  46. 科研绘图系列:python语言实验线图(line Chart)
  47. 科研绘图系列:R语言圆形柱状图(circular barplot)
  48. 科研绘图系列:R语言金字塔图(pyramid plot)
  49. 科研绘图系列:R语言分组散点图(grouped scatter plot)
  50. 科研绘图系列:R语言雷达图(radar plot)
  51. 科研绘图系列:R语言火山图(volcano plot)
  52. 科研绘图系列:R语言mantel_test结果可视化-CSDN博客
  53. 科研绘图系列:python语言分组条形图(grouped barplot plot)
  54. 科研绘图系列:python语言制标准差的直方图(STD histogram plot)
  55. 科研绘图系列:python语言tSNE散点图(tSNE scatter plot)
  56. 科研绘图系列:python语言散点图和密度分布图(scatter & density plot)
  57. 科研绘图系列:python语言密度分布图(density plot)
  58. 科研绘图系列:python语言散点相关系数图(scatter plot)
  59. 科研绘图系列:R语言PCoA图(PCoA plot)
  60. 科研绘图系列:R语言差异基因四分图(Quad plot)
  61. 科研绘图系列:R语言火山图+富集图(volcano + enrichment plot)
  62. 科研绘图系列:R语言组合图形绘图-CSDN博客
  63. 科研绘图系列:R语言基础图形合集-CSDN博客
  64. 科研绘图系列:R语言基因PPI互作网络图(PPI network plot )
  65. 科研绘图系列:R语言富集火山图和通路图(volcano plot & pathway)
  66. 科研绘图系列:R语言富集通路棒棒图(lollipop plot)
  67. 科研绘图系列:R语言单细胞差异基因四分图(Quad plot)
  68. 科研绘图系列:R语言热图和PCA(heatmap PCA)
  69. 科研绘图系列:R语言对角线矩阵图(corrplot plot)
  70. 科研绘图系列:R语言多组极坐标图(grouped polar plot)
  71. 科研绘图系列:Python语言时间趋势图-CSDN博客
  72. 科研绘图系列:Python语言箱线图-CSDN博客
  73. 科研绘图系列:Python语言时间序列线图-CSDN博客
  74. 科研绘图系列:R语言圆形条形图(circular barplot)
  75. 科研绘图系列:R语言GWAS圆圈曼哈顿图(Circular Manhattan plot)
  76. 科研绘图系列:R语言GWAS曼哈顿图(Manhattan plot)
  77. 科研绘图系列:R语言山脊图(Ridgeline Chart)
  78. 科研绘图系列:R语言和弦图 (Chord diagram)
  79. 科研绘图系列:R语言组合热图和散点图-CSDN博客
  80. 科研绘图系列:R语言组合堆积图(stacked barplot with multiple groups)
  81. 科研绘图系列:R语言TCGA分组饼图(multiple pie charts)
  82. 科研绘图系列:R语言单细胞聚类气泡图(single cell bubble)
  83. 科研绘图系列:R语言好看的饼图(pie charts)
  84. 科研绘图系列:R语言微生物堆积图(stacked barplot)
  85. 科研绘图系列:R语言circos图(circos plot)
  86. 科研绘图系列:R语言热图(heatmap)-CSDN博客
  87. 科研绘图系列:R语言饼图(pie chart)
  88. 科研绘图系列:R语言雨云图(Raincloud plot)
  89. 科研绘图系列:R语言分割小提琴图(Split-violin)-CSDN博客
  90. 科研绘图系列:R语言柱状图分布(histogram plot)
  91. 科研绘图系列:R语言柱状图分布2(histogram plot)
  92. 科研绘图系列:R语言折线图(linechart plots)
  93. 科研绘图系列:R语言多个图形组合(multiple plots)
  94. 科研绘图系列:ggpubr包绘制SCI图-CSDN博客
  95. 科研绘图系列:plot1cell单细胞可视化包-CSDN博客
  96. 科研绘图系列:DiagrammeR流程图-CSDN博客
  97. 科研绘图系列:TreeAndLeaf二分类树构建-CSDN博客
  98. 科研绘图系列:R语言线图等系列-CSDN博客
  99. 科研绘图系列:ggsci期刊配色-CSDN博客
  100. 科研绘图系列:R语言宏基因组堆积图(stacked barplot)
  101. 科研绘图系列:R语言宏基因组PCoA图(PCoA plot)
  102. 科研绘图系列:R语言火山图(volcano plot)
  103. 科研绘图系列:R语言富集散点图(enrichment scatter plot)
  104. 科研绘图系列:Python语言相关性对角矩阵计算-CSDN博客
  105. 科研绘图系列:R语言扩展物种堆积图(Extended Stacked Barplot)
  106. 科研绘图系列:R语言散点图和小提琴图(scatter plot & violin plot)
  107. 科研绘图系列:R语言箱线图(boxplot)-CSDN博客
  108. 科研绘图系列:R语言箱线图和连线图(boxplot & linechart)
  109. 科研绘图系列:R语言误差连线图(errobar linechart)
  110. 科研绘图系列:R语言多个AUC曲线图(multiple AUC curves)
  111. 科研绘图系列:R语言树结构聚类热图(cluster heatmap)
  112. 科研绘图系列:R语言组合多个图形-CSDN博客
  113. 科研绘图系列:R语言ggplot2画热图(heatmap)-CSDN博客
  114. 科研绘图系列:R语言ggplot2画热图2(heatmap)-CSDN博客
  115. 科研绘图系列:R语言堆积图(stacked barplot)
  116. 科研绘图系列:R语言ggplot2画热图3(heatmap)-CSDN博客
  117. 科研绘图系列:R语言分组堆积图(stacked barplot)
  118. 科研绘图系列:R语言分组热图(heatmap)-CSDN博客
  119. 科研绘图系列:R语言连线点图(linechart dotplot)
  120. 科研绘图系列:Python语言网络图绘制-CSDN博客
  121. 科研绘图系列:线性回归计算嵌套的组间OR森林图-CSDN博客
  122. 科研绘图系列:R语言绘制SCI文章图2
  123. 科研绘图系列:R语言绘制中国地理地图_用r语言绘制中国地图-CSDN博客
  124. 科研绘图系列:R语言蝴蝶图(Butterfly Chart)
  125. 科研绘图系列:R语言象限热图(quadrant heatmap)
  126. 科研绘图系列:R语言散点相关系数图(scatter plot)
  127. 科研绘图系列:R语言柱状图(histogram)-CSDN博客
  128. 科研绘图系列:R语言突出强调部分的饼图(pie plot)
  129. 科研绘图系列:R语言极坐标饼图(pie plot)

介绍

python语言的科研绘图合集

导入数据

数据可从以下链接下载(画图所需要的所有数据):

函数模块

从百度网盘拿到脚本tol_colors.py

代码语言:python
代码运行次数:0
运行
复制
import numpy as np
from matplotlib.colors import LinearSegmentedColormap, to_rgba_array


def discretemap(colormap, hexclrs):
    """
    Produce a colormap from a list of discrete colors without interpolation.
    """
    clrs = to_rgba_array(hexclrs)
    clrs = np.vstack([clrs[0], clrs, clrs[-1]])
    cdict = {}
    for ki, key in enumerate(('red','green','blue')):
        cdict[key] = [ (i/(len(clrs)-2.), clrs[i, ki], clrs[i+1, ki]) for i in range(len(clrs)-1) ]
    return LinearSegmentedColormap(colormap, cdict)


class TOLcmaps(object):
    """
    Class TOLcmaps definition.
    """
    def __init__(self):
        """
        """
        self.cmap = None
        self.cname = None
        self.namelist = (
            'sunset_discrete', 'sunset', 'BuRd_discrete', 'BuRd',
            'PRGn_discrete', 'PRGn', 'YlOrBr_discrete', 'YlOrBr', 'WhOrBr',
            'iridescent', 'rainbow_PuRd', 'rainbow_PuBr', 'rainbow_WhRd',
            'rainbow_WhBr', 'rainbow_discrete')

        self.funcdict = dict(
            zip(self.namelist,
                (self.__sunset_discrete, self.__sunset, self.__BuRd_discrete,
                self.__BuRd, self.__PRGn_discrete, self.__PRGn,
                self.__YlOrBr_discrete, self.__YlOrBr, self.__WhOrBr,
                self.__iridescent, self.__rainbow_PuRd, self.__rainbow_PuBr,
                self.__rainbow_WhRd, self.__rainbow_WhBr,
                self.__rainbow_discrete)))

    def __sunset_discrete(self):
        """
        Define colormap 'sunset_discrete'.
        """
        clrs = ['#364B9A', '#4A7BB7', '#6EA6CD', '#98CAE1', '#C2E4EF',
                '#EAECCC', '#FEDA8B', '#FDB366', '#F67E4B', '#DD3D2D',
                '#A50026']
        self.cmap = discretemap(self.cname, clrs)
        self.cmap.set_bad('#FFFFFF')

    def __sunset(self):
        """
        Define colormap 'sunset'.
        """
        clrs = ['#364B9A', '#4A7BB7', '#6EA6CD', '#98CAE1', '#C2E4EF',
                '#EAECCC', '#FEDA8B', '#FDB366', '#F67E4B', '#DD3D2D',
                '#A50026']
        self.cmap = LinearSegmentedColormap.from_list(self.cname, clrs)
        self.cmap.set_bad('#FFFFFF')

    def __BuRd_discrete(self):
        """
        Define colormap 'BuRd_discrete'.
        """
        clrs = ['#2166AC', '#4393C3', '#92C5DE', '#D1E5F0', '#F7F7F7',
                '#FDDBC7', '#F4A582', '#D6604D', '#B2182B']
        self.cmap = discretemap(self.cname, clrs)
        self.cmap.set_bad('#FFEE99')

    def __BuRd(self):
        """
        Define colormap 'BuRd'.
        """
        clrs = ['#2166AC', '#4393C3', '#92C5DE', '#D1E5F0', '#F7F7F7',
                '#FDDBC7', '#F4A582', '#D6604D', '#B2182B']
        self.cmap = LinearSegmentedColormap.from_list(self.cname, clrs)
        self.cmap.set_bad('#FFEE99')

    def __PRGn_discrete(self):
        """
        Define colormap 'PRGn_discrete'.
        """
        clrs = ['#762A83', '#9970AB', '#C2A5CF', '#E7D4E8', '#F7F7F7',
                '#D9F0D3', '#ACD39E', '#5AAE61', '#1B7837']
        self.cmap = discretemap(self.cname, clrs)
        self.cmap.set_bad('#FFEE99')

    def __PRGn(self):
        """
        Define colormap 'PRGn'.
        """
        clrs = ['#762A83', '#9970AB', '#C2A5CF', '#E7D4E8', '#F7F7F7',
                '#D9F0D3', '#ACD39E', '#5AAE61', '#1B7837']
        self.cmap = LinearSegmentedColormap.from_list(self.cname, clrs)
        self.cmap.set_bad('#FFEE99')

    def __YlOrBr_discrete(self):
        """
        Define colormap 'YlOrBr_discrete'.
        """
        clrs = ['#FFFFE5', '#FFF7BC', '#FEE391', '#FEC44F', '#FB9A29',
                '#EC7014', '#CC4C02', '#993404', '#662506']
        self.cmap = discretemap(self.cname, clrs)
        self.cmap.set_bad('#888888')

    def __YlOrBr(self):
        """
        Define colormap 'YlOrBr'.
        """
        clrs = ['#FFFFE5', '#FFF7BC', '#FEE391', '#FEC44F', '#FB9A29',
                '#EC7014', '#CC4C02', '#993404', '#662506']
        self.cmap = LinearSegmentedColormap.from_list(self.cname, clrs)
        self.cmap.set_bad('#888888')

    def __WhOrBr(self):
        """
        Define colormap 'WhOrBr'.
        """
        clrs = ['#FFFFFF', '#FFF7BC', '#FEE391', '#FEC44F', '#FB9A29',
                '#EC7014', '#CC4C02', '#993404', '#662506']
        self.cmap = LinearSegmentedColormap.from_list(self.cname, clrs)
        self.cmap.set_bad('#888888')

    def __iridescent(self):
        """
        Define colormap 'iridescent'.
        """
        clrs = ['#FEFBE9', '#FCF7D5', '#F5F3C1', '#EAF0B5', '#DDECBF',
                '#D0E7CA', '#C2E3D2', '#B5DDD8', '#A8D8DC', '#9BD2E1',
                '#8DCBE4', '#81C4E7', '#7BBCE7', '#7EB2E4', '#88A5DD',
                '#9398D2', '#9B8AC4', '#9D7DB2', '#9A709E', '#906388',
                '#805770', '#684957', '#46353A']
        self.cmap = LinearSegmentedColormap.from_list(self.cname, clrs)
        self.cmap.set_bad('#999999')

    def __rainbow_PuRd(self):
        """
        Define colormap 'rainbow_PuRd'.
        """
        clrs = ['#6F4C9B', '#6059A9', '#5568B8', '#4E79C5', '#4D8AC6',
                '#4E96BC', '#549EB3', '#59A5A9', '#60AB9E', '#69B190',
                '#77B77D', '#8CBC68', '#A6BE54', '#BEBC48', '#D1B541',
                '#DDAA3C', '#E49C39', '#E78C35', '#E67932', '#E4632D',
                '#DF4828', '#DA2222']
        self.cmap = LinearSegmentedColormap.from_list(self.cname, clrs)
        self.cmap.set_bad('#FFFFFF')

    def __rainbow_PuBr(self):
        """
        Define colormap 'rainbow_PuBr'.
        """
        clrs = ['#6F4C9B', '#6059A9', '#5568B8', '#4E79C5', '#4D8AC6',
                '#4E96BC', '#549EB3', '#59A5A9', '#60AB9E', '#69B190',
                '#77B77D', '#8CBC68', '#A6BE54', '#BEBC48', '#D1B541',
                '#DDAA3C', '#E49C39', '#E78C35', '#E67932', '#E4632D',
                '#DF4828', '#DA2222', '#B8221E', '#95211B', '#721E17',
                '#521A13']
        self.cmap = LinearSegmentedColormap.from_list(self.cname, clrs)
        self.cmap.set_bad('#FFFFFF')

    def __rainbow_WhRd(self):
        """
        Define colormap 'rainbow_WhRd'.
        """
        clrs = ['#E8ECFB', '#DDD8EF', '#D1C1E1', '#C3A8D1', '#B58FC2',
                '#A778B4', '#9B62A7', '#8C4E99', '#6F4C9B', '#6059A9',
                '#5568B8', '#4E79C5', '#4D8AC6', '#4E96BC', '#549EB3',
                '#59A5A9', '#60AB9E', '#69B190', '#77B77D', '#8CBC68',
                '#A6BE54', '#BEBC48', '#D1B541', '#DDAA3C', '#E49C39',
                '#E78C35', '#E67932', '#E4632D', '#DF4828', '#DA2222']
        self.cmap = LinearSegmentedColormap.from_list(self.cname, clrs)
        self.cmap.set_bad('#666666')

    def __rainbow_WhBr(self):
        """
        Define colormap 'rainbow_WhBr'.
        """
        clrs = ['#E8ECFB', '#DDD8EF', '#D1C1E1', '#C3A8D1', '#B58FC2',
                '#A778B4', '#9B62A7', '#8C4E99', '#6F4C9B', '#6059A9',
                '#5568B8', '#4E79C5', '#4D8AC6', '#4E96BC', '#549EB3',
                '#59A5A9', '#60AB9E', '#69B190', '#77B77D', '#8CBC68',
                '#A6BE54', '#BEBC48', '#D1B541', '#DDAA3C', '#E49C39',
                '#E78C35', '#E67932', '#E4632D', '#DF4828', '#DA2222',
                '#B8221E', '#95211B', '#721E17', '#521A13']
        self.cmap = LinearSegmentedColormap.from_list(self.cname, clrs)
        self.cmap.set_bad('#666666')

    def __rainbow_discrete(self, lut=None):
        """
        Define colormap 'rainbow_discrete'.
        """
        clrs = ['#E8ECFB', '#D9CCE3', '#D1BBD7', '#CAACCB', '#BA8DB4',
                '#AE76A3', '#AA6F9E', '#994F88', '#882E72', '#1965B0',
                '#437DBF', '#5289C7', '#6195CF', '#7BAFDE', '#4EB265',
                '#90C987', '#CAE0AB', '#F7F056', '#F7CB45', '#F6C141',
                '#F4A736', '#F1932D', '#EE8026', '#E8601C', '#E65518',
                '#DC050C', '#A5170E', '#72190E', '#42150A']
        indexes = [[9], [9, 25], [9, 17, 25], [9, 14, 17, 25], [9, 13, 14, 17,
                25], [9, 13, 14, 16, 17, 25], [8, 9, 13, 14, 16, 17, 25], [8,
                9, 13, 14, 16, 17, 22, 25], [8, 9, 13, 14, 16, 17, 22, 25, 27],
                [8, 9, 13, 14, 16, 17, 20, 23, 25, 27], [8, 9, 11, 13, 14, 16,
                17, 20, 23, 25, 27], [2, 5, 8, 9, 11, 13, 14, 16, 17, 20, 23,
                25], [2, 5, 8, 9, 11, 13, 14, 15, 16, 17, 20, 23, 25], [2, 5,
                8, 9, 11, 13, 14, 15, 16, 17, 19, 21, 23, 25], [2, 5, 8, 9, 11,
                13, 14, 15, 16, 17, 19, 21, 23, 25, 27], [2, 4, 6, 8, 9, 11,
                13, 14, 15, 16, 17, 19, 21, 23, 25, 27], [2, 4, 6, 7, 8, 9, 11,
                13, 14, 15, 16, 17, 19, 21, 23, 25, 27], [2, 4, 6, 7, 8, 9, 11,
                13, 14, 15, 16, 17, 19, 21, 23, 25, 26, 27], [1, 3, 4, 6, 7, 8,
                9, 11, 13, 14, 15, 16, 17, 19, 21, 23, 25, 26, 27], [1, 3, 4,
                6, 7, 8, 9, 10, 12, 13, 14, 15, 16, 17, 19, 21, 23, 25, 26,
                27], [1, 3, 4, 6, 7, 8, 9, 10, 12, 13, 14, 15, 16, 17, 18, 20,
                22, 24, 25, 26, 27], [1, 3, 4, 6, 7, 8, 9, 10, 12, 13, 14, 15,
                16, 17, 18, 20, 22, 24, 25, 26, 27, 28], [0, 1, 3, 4, 6, 7, 8,
                9, 10, 12, 13, 14, 15, 16, 17, 18, 20, 22, 24, 25, 26, 27, 28]]
        if lut == None or lut < 1 or lut > 23:
            lut = 22
        self.cmap = discretemap(self.cname, [ clrs[i] for i in indexes[lut-1] ])
        if lut == 23:
            self.cmap.set_bad('#777777')
        else:
            self.cmap.set_bad('#FFFFFF')

    def show(self):
        """
        List names of defined colormaps.
        """
        print(' '.join(repr(n) for n in self.namelist))

    def get(self, cname='rainbow_PuRd', lut=None):
        """
        Return requested colormap, default is 'rainbow_PuRd'.
        """
        self.cname = cname
        if cname == 'rainbow_discrete':
            self.__rainbow_discrete(lut)
        else:
            self.funcdict[cname]()
        return self.cmap


def tol_cmap(colormap=None, lut=None):
    """
    Continuous and discrete color sets for ordered data.
    
    Return a matplotlib colormap.
    Parameter lut is ignored for all colormaps except 'rainbow_discrete'.
    """
    obj = TOLcmaps()
    if colormap == None:
        return obj.namelist
    if colormap not in obj.namelist:
        colormap = 'rainbow_PuRd'
        print('*** Warning: requested colormap not defined,',
              'known colormaps are {}.'.format(obj.namelist),
              'Using {}.'.format(colormap))
    return obj.get(colormap, lut)


def tol_cset(colorset=None):
    """
    Discrete color sets for qualitative data.

    Define a namedtuple instance with the colors.
    Examples for: cset = tol_cset(<scheme>)
      - cset.red and cset[1] give the same color (in default 'bright' colorset)
      - cset._fields gives a tuple with all color names
      - list(cset) gives a list with all colors
    """
    from collections import namedtuple
    
    namelist = ('bright', 'high-contrast', 'vibrant', 'muted', 'medium-contrast', 'light')
    if colorset == None:
        return namelist
    if colorset not in namelist:
        colorset = 'bright'
        print('*** Warning: requested colorset not defined,',
              'known colorsets are {}.'.format(namelist),
              'Using {}.'.format(colorset)) 

    if colorset == 'bright':
        cset = namedtuple('Bcset',
                    'blue red green yellow cyan purple grey black')
        return cset('#4477AA', '#EE6677', '#228833', '#CCBB44', '#66CCEE',
                    '#AA3377', '#BBBBBB', '#000000')

    if colorset == 'high-contrast':
        cset = namedtuple('Hcset',
                    'blue yellow red black')
        return cset('#004488', '#DDAA33', '#BB5566', '#000000')

    if colorset == 'vibrant':
        cset = namedtuple('Vcset',
                    'orange blue cyan magenta red teal grey black')
        return cset('#EE7733', '#0077BB', '#33BBEE', '#EE3377', '#CC3311',
                    '#009988', '#BBBBBB', '#000000')

    if colorset == 'muted':
        cset = namedtuple('Mcset',
                    'rose indigo sand green cyan wine teal olive purple pale_grey black')
        return cset('#CC6677', '#332288', '#DDCC77', '#117733', '#88CCEE',
                    '#882255', '#44AA99', '#999933', '#AA4499', '#DDDDDD',
                    '#000000')

    if colorset == 'medium-contrast':
        cset = namedtuple('Mcset',
                    'light_blue dark_blue light_yellow dark_red dark_yellow light_red black')
        return cset('#6699CC', '#004488', '#EECC66', '#994455', '#997700',
                    '#EE99AA', '#000000')

    if colorset == 'light':
        cset = namedtuple('Lcset',
                    'light_blue orange light_yellow pink light_cyan mint pear olive pale_grey black')
        return cset('#77AADD', '#EE8866', '#EEDD88', '#FFAABB', '#99DDFF',
                    '#44BB99', '#BBCC33', '#AAAA00', '#DDDDDD', '#000000')


def main():

    from matplotlib import pyplot as plt

    # Change default colorset (for lines) and colormap (for maps).
#    plt.rc('axes', prop_cycle=plt.cycler('color', list(tol_cset('bright'))))
#    plt.cm.register_cmap('rainbow_PuRd', tol_cmap('rainbow_PuRd'))
#    plt.rc('image', cmap='rainbow_PuRd')

    # Show colorsets tol_cset(<scheme>).
    schemes = tol_cset()
    fig, axes = plt.subplots(ncols=len(schemes), figsize=(9, 3))
    fig.subplots_adjust(top=0.9, bottom=0.02, left=0.02, right=0.92)
    for ax, scheme in zip(axes, schemes):
        cset = tol_cset(scheme)
        names = cset._fields
        colors = list(cset)
        for name, color in zip(names, colors):
            ax.scatter([], [], c=color, s=80, label=name)
        ax.set_axis_off()
        ax.legend(loc=2)
        ax.set_title(scheme)
    plt.show()

    # Show colormaps tol_cmap(<scheme>). 
    schemes = tol_cmap()
    gradient = np.linspace(0, 1, 256)
    gradient = np.vstack((gradient, gradient))
    fig, axes = plt.subplots(nrows=len(schemes))
    fig.subplots_adjust(top=0.98, bottom=0.02, left=0.2, right=0.99)
    for ax, scheme in zip(axes, schemes):
        pos = list(ax.get_position().bounds)
        ax.set_axis_off()
        ax.imshow(gradient, aspect=4, cmap=tol_cmap(scheme))
        fig.text(pos[0] - 0.01, pos[1] + pos[3]/2., scheme, va='center', ha='right', fontsize=10)
    plt.show()

    # Show colormaps tol_cmap('rainbow_discrete', <lut>). 
    gradient = np.linspace(0, 1, 256)
    gradient = np.vstack((gradient, gradient))
    fig, axes = plt.subplots(nrows=23)
    fig.subplots_adjust(top=0.98, bottom=0.02, left=0.25, right=0.99)
    for lut, ax in enumerate(axes, start=1):
        pos = list(ax.get_position().bounds)
        ax.set_axis_off()
        ax.imshow(gradient, aspect=4, cmap=tol_cmap('rainbow_discrete', lut))
        fig.text(pos[0] - 0.01, pos[1] + pos[3]/2., 'rainbow_discrete, ' + str(lut), va='center', ha='right', fontsize=10)
    plt.show()


if __name__ == '__main__':
    main()

画图

画图脚本在百度网盘中,解压即可获得。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 介绍
  • 导入数据
  • 函数模块
  • 画图
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档