python colormap 顺滑_如何在python matplotlib colormap中提高颜色分辨率

Warren Weckesser's comments绝对有效,可以给你一个高分辨率的图像。我在下面的例子中实现了他的想法。在

关于使用contourf(),我不确定这是否是一个与版本相关的问题,但是在最新的版本中,

^{}没有N的kwarg。在

正如您在文档中看到的,您希望使用N作为参数(语法:contourf(X,Y,Z,N))来指定要绘制的级别,而不是RGB像素的数量。contourf()绘制填充轮廓,分辨率取决于要绘制的级别数。您的N=256将不执行任何操作,contourf()将自动选择{a3}。在

下面的代码是从官方的example修改的,比较不同N的分辨率。如果存在版本问题,此代码将使用python 3.5.2; matplotlib 1.5.3给出以下绘图:import numpy as np

import matplotlib.pyplot as plt

delta = 0.025

x = y = np.arange(-3.0, 3.01, delta)

X, Y = np.meshgrid(x, y)

Z1 = plt.mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)

Z2 = plt.mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)

Z = 10 * (Z1 - Z2)

fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2)

fig.set_size_inches(8, 6)

# Your code sample

CS1 = ax1.contourf(X, Y, Z, cmap="viridis", N=256)

ax1.set_title('Your code sample')

ax1.set_xlabel('word length anomaly')

ax1.set_ylabel('sentence length anomaly')

cbar1 = fig.colorbar(CS1, ax=ax1)

# Contour up to N=7 automatically-chosen levels,

# which should give the same as your code.

N = 7

CS2 = ax2.contourf(X, Y, Z, N, cmap="viridis")

ax2.set_title('N=7')

ax2.set_xlabel('word length anomaly')

ax2.set_ylabel('sentence length anomaly')

cbar2 = fig.colorbar(CS2, ax=ax2)

# Contour up to N=100 automatically-chosen levels.

# The resolution is still not as high as using imshow().

N = 100

CS3 = ax3.contourf(X, Y, Z, N, cmap="viridis")

ax3.set_title('N=100')

ax3.set_xlabel('word length anomaly')

ax3.set_ylabel('sentence length anomaly')

cbar3 = fig.colorbar(CS3, ax=ax3)

IM = ax4.imshow(Z, cmap="viridis", origin='lower', extent=(-3, 3, -3, 3))

ax4.set_title("Warren Weckesser's idea")

ax4.set_xlabel('word length anomaly')

ax4.set_ylabel('sentence length anomaly')

cbar4 = fig.colorbar(IM, ax=ax4)

fig.tight_layout()

plt.show()

bo4iW.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值