最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python如何查看并打印matplotlib中所有的colormap(cmap)類型

 更新時間:2022年11月03日 11:33:49   作者:勤奮的大熊貓  
這篇文章主要介紹了Python如何查看并打印matplotlib中所有的colormap(cmap)類型,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教

查看并打印matplotlib中所有的colormap(cmap)類型

代碼如下:

方法一

import matplotlib.pyplot as plt

cmaps = sorted(m for m in plt.cm.datad if not m.endswith("_r"))
print(cmaps)

我們忽略以_r結尾的類型,因為它們都是類型后面不帶有_r的反轉版本(reversed version)。

所有的類型我們可以在matplotlib的源代碼中找到:(如下圖)

方法二

import matplotlib.pyplot as plt

cmap_list1 = plt.colormaps()
print(cmap_list1)

方法三

如果使用的是Pycharm編譯器,那么可以在作圖的時候簡單的隨便給定一個cmap的類型,如果給定的cmap類型是錯誤的,那么在編譯器的錯誤提示信息中也會顯示出所有的cmap類型。

比如,我們這里我們想要做一個高斯函數(shù)的曲面分布圖,我們隨意給cmap一個'aaa'的值,這時,我們可以在編譯器提示窗口看到如下錯誤信息的輸出。

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

x = np.linspace(-3, 3, 100)
y = np.linspace(-3, 3, 100)
x, y = np.meshgrid(x, y)
w0 = 1
gaussian = np.exp(-((pow(x, 2) + pow(y, 2)) / pow(w0, 2)))

fig = plt.figure()
ax = Axes3D(fig)
ax.plot_surface(x, y, gaussian, cmap='aaa')
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
plt.show()
"""
錯誤提示信息:
ValueError: 'aaa' is not a valid value for name; supported values are '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', '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', 'cividis', 'cividis_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', 'spring', 'spring_r', 'summer', 'summer_r', 'tab10','tab10_r',
'tab20', 'tab20_r', 'tab20b', 'tab20b_r', 'tab20c', 'tab20c_r', 'terrain','terrain_r',
'turbo', 'turbo_r', 'twilight', 'twilight_r', 'twilight_shifted','twilight_shifted_r',
'viridis', 'viridis_r', 'winter', 'winter_r'
"""

matplotlib cmap取值問題

直接定義一個類來獲取cmap中各個顏色方便使用 

使用的話:mycolor = MyColor(‘Accent’); mycolor.get_color();# 每次就調用獲取下一個cmap中的顏色。

class MyColor(object):
    def __init__(self, cmap_name):
        self.color_set  = plt.get_cmap(cmap_name).colors
        self.idx = 0
        self.color_len = len(self.color_set)
        
    def get_color(self):
        if self.idx == self.color_len - 1:
            self.idx = 0
        color = self.color_set[self.idx]
        self.idx += 1
        return color

可視化官方提供的cmap

比如查看:[‘Pastel1’, ‘Pastel2’, ‘Paired’, ‘Accent’, ‘Dark2’, ‘Set1’, ‘Set2’, ‘Set3’, ‘tab10’, ‘tab20’, ‘tab20b’, ‘tab20c’]

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

cmaps = {}
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 colormaps
    nrows = len(cmap_list)
    figh = 0.35 + 0.15 + (nrows + (nrows - 1) * 0.1) * 0.22
    fig, axs = plt.subplots(nrows=nrows + 1, figsize=(6.4, figh), dpi=100)
    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=plt.get_cmap(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_list
    

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

運行后:

以上為個人經驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關文章

  • Python數(shù)據(jù)結構樹與算法分析

    Python數(shù)據(jù)結構樹與算法分析

    這篇文章主要介紹了Python數(shù)據(jù)結構樹與算法分析,文章圍繞主題展開詳細的內容介紹,具有一定的參考價值,需要的小伙伴可以參考一下
    2022-07-07
  • Python報錯error: subprocess-exited-with-error解決辦法

    Python報錯error: subprocess-exited-with-error解決辦法

    在Python開發(fā)中,遇到subprocess-exited-with-error通常是由依賴缺失、權限問題、環(huán)境配置錯誤或兼容性問題導致,修復方法包括安裝依賴、使用虛擬環(huán)境、提升權限、檢查路徑和命令,文中通過代碼介紹的非常詳細,需要的朋友可以參考下
    2024-10-10
  • 分析Python字符串拼接+=和join()哪個速度更快

    分析Python字符串拼接+=和join()哪個速度更快

    這篇文章主要分析了Python中字符串拼接+=和join()哪個速度更快,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-02-02
  • 基于python使用OpenCV進行物體輪廓排序

    基于python使用OpenCV進行物體輪廓排序

    這篇文章主要介紹了基于python使用OpenCV進行物體輪廓排序,在進行圖像處理過程中,我們經常會遇到一些和物體輪廓相關的操作,我們直接使用Opencv的findContours函數(shù)可以很容易的得到每個目標的輪廓,但是可視化后,?這個次序是無序的,更多相關資料請參考下面文章內容
    2022-01-01
  • python thread 并發(fā)且順序運行示例

    python thread 并發(fā)且順序運行示例

    以上源文件是對python中的線程的一個簡單應用,實現(xiàn)了對并發(fā)線程的順序運行,也許對你會有小小幫助
    2009-04-04
  • Python queue模塊攻略全解

    Python queue模塊攻略全解

    這篇文章主要為大家介紹了Python queue模塊攻略全解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-12-12
  • Python3轉換html到pdf的不同解決方案

    Python3轉換html到pdf的不同解決方案

    今天小編就為大家分享一篇關于Python3轉換html到pdf的不同解決方案,小編覺得內容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧
    2019-03-03
  • 利用Python的裝飾器解決Bottle框架中用戶驗證問題

    利用Python的裝飾器解決Bottle框架中用戶驗證問題

    這篇文章主要介紹了Python的Bottle框架中解決用戶驗證問題,代碼基于Python2.x版本,需要的朋友可以參考下
    2015-04-04
  • keras 多gpu并行運行案例

    keras 多gpu并行運行案例

    這篇文章主要介紹了keras 多gpu并行運行案例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-06-06
  • 一文帶你詳解Python中sys.executable函數(shù)的作用

    一文帶你詳解Python中sys.executable函數(shù)的作用

    sys.executable函數(shù)是用來獲取當前Python解釋器的完整路徑的,本文主要介紹了一文帶你詳解Python中sys.executable函數(shù)的作用,具有一定的參考價值,感興趣的可以了解一下
    2024-03-03

最新評論

慈利县| 宜章县| 洛川县| 柳河县| 芜湖县| 吴忠市| 宣武区| 交城县| 翼城县| 绥化市| 公主岭市| 白银市| 玛沁县| 金秀| 定襄县| 彭阳县| 汶川县| 木兰县| 疏勒县| 永平县| 祁东县| 太康县| 梨树县| 鄂伦春自治旗| 大宁县| 平远县| 郧西县| 彩票| 高邑县| 浪卡子县| 怀远县| 陆川县| 仪征市| 探索| 水富县| 汤原县| 和平县| 元谋县| 蚌埠市| 黎川县| 叶城县|