我有以下2个错误:
AttributeError: Unknown property cmap
和
Cannot find reference 'coolwarm' in 'cm.py'
我跑了:
import matplotlib.pyplot as plt
import matplotlib
import matplotlib.cm as cm
代码我收到的错误是
fig = plt.figure()
ax1 = fig.add_subplot(111)
ax2 = ax1.twiny()
ax1.plot(result['tme'], result['spread'], ".", markersize=1,
c=result['bdaterange'], cmap=cm.coolwarm)
答案 0 :(得分:2)
自1.1.0(commit)以来,色彩映射###################################################
# I've created a test directory to try my script against
###################################################
<# Start 7/4/2017 #>
Set-Location 'D:\IT Notes\psroot'
<# Make directories A..Z#>
65..90 | % {md ("{0}" -f [char]$_)}
<# Make a list of 0-9, A-Z, & a-z #>
$chars = [char[]] ([char]'0'..[char]'9' + [char]'A'..[char]'Z' + [char]'a'..[char]'z')
<# Use chars list to create random.txt file#>
(1..100).ForEach({-join (Get-Random $chars -Count 10) | Add-Content random.txt })
<# Save random.txt list to a variable#>
$random = (Get-Content .\random.txt)
<# Create files & add .txt extension #>
New-Item $random -ItemType file | Rename-Item -NewName {$_.name + ".txt"}
###################################################
被添加到matplotlib。
之后更新你的matplotlib然后你就可以了。
coolwarm
答案 1 :(得分:0)
这可能就是你要做的事情(你的问题有点模糊,所以,我猜)。
首先,一些导入和随机数据:
import matplotlib.pyplot as plt
import matplotlib.colors as colors
import matplotlib.cm as cm
import numpy as np
xs = np.arange(10)
ys = np.arange(10,20)
# the intensity of each data point
intensities = np.random.rand(10)
然后,我们得到你想要的色彩图:
coolwarm = plt.get_cmap('coolwarm')
my_norm = colors.Normalize(0, 1)
map = cm.ScalarMappable(norm=my_norm, cmap='coolwarm')
最后,绘制每个数据点的强度如下:
for idx in range(len(ys)):
point_x = xs[idx]
point_y = ys[idx]
my_col = map.to_rgba(intensities[idx])
plt.plot(point_x, point_y, ".", markersize=5, color=my_col)
plt.show()
对于此代码,您将获得如下图像: random_cmap_data