有人知道——在Matplotlib中——如何用半透明的颜色生成好看的填充等高线图吗?如果向contourf()传递半透明颜色的颜色贴图,则填充区域之间会产生小间隙:
根据docs,这不是一个bug(“contourf()[…]不绘制多边形边”)。要绘制边缘,建议“添加调用contour()的线条轮廓”。但这看起来也不好,因为边缘变得太不透明:
您可以使用linewidth的linewidth参数,但这没有多大帮助。有什么想法吗?在
下面是重现问题的代码(我使用面向对象的API,但结果与pyplot相同):import matplotlib
import numpy as np
from matplotlib.figure import Figure
from matplotlib.backends.backend_agg import FigureCanvasAgg
# generate some data
shape = (100, 100)
x_rng = np.linspace(-1, 1, shape[1])
y_rng = np.linspace(-1, 1, shape[0])
x, y = np.meshgrid(x_rng, y_rng)
z = np.sqrt(x**2 + y**2)
# create figure
width_inch, height_inch = 5, 5 # results in 500x500px with dpi