本文介绍了如何在 Windows 上使用 pip for Spyder (Python 3.5) 安装颜色图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用cmap_builder,所以我试过了from colormap import cmap_builder.当我尝试时,Spyder 向我抛出了一个错误ImportError: 没有名为colormap"的模块

所以我尝试安装,pip install colormap

可以像这样创建一个离散的颜色图:

cmap = mcolors.ListedColormap(["深红色","金色","钢蓝色"])

I want to use cmap_builder, So I triedfrom colormap import cmap_builder.When I tried, Spyder throwed me an errorImportError: No module named 'colormap'

So I tried installing, pip install colormap as described in http://colormap.readthedocs.io/en/latest/This didn't work and displayed a messageNo matching distribution found

So is there a different way to install colormap for python 3.5 to use on Spyder ?

解决方案

In principle matplotlib already has all the tools available to create custom colormaps. The two main options are to create a segmented colormap, LinearSegmentedColormap or a discrete colormap ListedColormap.

Find here an example of a continuous colormap between crimson, gold and blue:

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

cmap = mcolors.LinearSegmentedColormap.from_list("n", ["crimson", "gold","steelblue"])

x = np.linspace(-1,2.7)
X,Y = np.meshgrid(x,x)
Z = np.exp(-X**2-Y**2)

im =plt.imshow(Z, cmap=cmap)
plt.colorbar()

plt.show()

A discrete colormap could be created like this:

cmap = mcolors.ListedColormap(["crimson", "gold","steelblue"])

这篇关于如何在 Windows 上使用 pip for Spyder (Python 3.5) 安装颜色图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-13 20:38