如何绘制轮廓图?

时间:2018-09-27 05:47:15

标签: python-3.x matplotlib

在我的代码中,我没有正确获得计数器图,您能否帮助我如何在此链接下绘制计数器图enter image description here

以下是我的代码:

import matplotlib.pyplot as plt
import numpy as np
from matplotlib.image import BboxImage
from matplotlib.transforms import Bbox, TransformedBbox
import matplotlib.animation as animation


fig, (ax1) = plt.subplots(ncols=1)



# Create a BboxImage for each colormap
# ------------------------------------
a = np.linspace(0, 1, 256).reshape(1, -1)
a = np.vstack((a, a))

# List of all colormaps; skip reversed colormaps.
maps = sorted(m for m in plt.cm.cmap_d if not m.endswith("_r"))

ncol = 1
nrow = len(maps)//ncol + 1

xpad_fraction = 0.3
dx = 1./(ncol + xpad_fraction*(ncol - 1))

ypad_fraction = 0.3
dy = 1./(nrow + ypad_fraction*(nrow - 1))

for i, m in enumerate(maps):
    ix, iy = divmod(i, nrow)

    bbox0 = Bbox.from_bounds(ix*dx*(1 + xpad_fraction),
                             1. - iy*dy*(1 + ypad_fraction) - dy,
                             dx, dy)
    bbox = TransformedBbox(bbox0, ax1.transAxes)

    bbox_image = BboxImage(bbox,
                           cmap=plt.get_cmap(m),
                           norm=None,
                           origin=None,
                           # **kwargs
                           )

    bbox_image.set_data(a)
    ax1.add_artist(bbox_image)

plt.show()

我越来越像这样,但我想绘制一个enter image description here我的上图所示的反图。您能指导我如何绘制吗?

0 个答案:

没有答案