如何在matplotlib(Python)中制作数据的颜色图?

时间:2015-11-19 20:14:16

标签: matplotlib color-mapping

听一下我很长的数据文件:

330.0000, 340.0000, 2.336e-9
340.0000, 340.0000, 2.346e-9
350.0000, 340.0000, 2.303e-9
360.0000, 340.0000, 2.329e-9
340.0000, 340.0000, 2.338e-9
380.0000, 340.0000, 2.335e-9
390.0000, 340.0000, 2.343e-9

如何制作色彩图?它应该是这样的:

Colormap

这是我到目前为止所尝试的based on the manual

import numpy as np
import matplotlib.pyplot as plt

nrows = max(len(cmap_list) for cmap_category, cmap_list in cmaps)
gradient =  []
with open('inputfile.txt') as inputfile:
    for line in inputfile:
        results.append(line.strip().split(','))
gradient = np.vstack((gradient, gradient))


def plot_color_gradients(cmap_category, cmap_list):
    fig, axes = plt.subplots(nrows=nrows)
    fig.subplots_adjust(top=0.95, bottom=0.01, left=0.2, right=0.99)
    axes[0].set_title(cmap_category + ' colormaps', fontsize=14)

    for ax, name in zip(axes, cmap_list):
        ax.imshow(gradient, aspect='auto', cmap=plt.get_cmap(name))
        pos = list(ax.get_position().bounds)
        x_text = pos[0] - 0.01
        y_text = pos[1] + pos[3]/2.
        fig.text(x_text, y_text, name, va='center', ha='right', fontsize=10)

    # Turn off *all* ticks & spines, not just the ones with colormaps.
    for ax in axes:
        ax.set_axis_off()

for cmap_category, cmap_list in cmaps:
    plot_color_gradients(cmap_category, cmap_list)

plt.show()

希望你能帮助我。

0 个答案:

没有答案