Matplotlib中如何生成清晰易读的灰度线图?

3
我是一名计算机科学本科生。在我的大多数课程中,我需要制作某种图表来展示我的结果。我的大多数教授希望这些图表能够打印出来(或者,如果他们接受PDF格式,他们会自己打印出一份),以便于评分。我使用 matplotlib 与其他一些工具结合使用来生成这些图表,效果不错。
然而,我的问题在于我打印出来的(有色)线条图表往往难以辨认。一个相对温和的例子是:
一个更糟糕的例子(可能更多地涉及到图表本身的设计)是:
当打印成黑白图像时,数据系列变得无法区分。
下面是我用来生成图表的其中一个脚本的示例。我真的想找到一种方法,使打印出来的图表在黑白打印机上看起来尽可能清晰——我该怎么做?哪些技巧最有效地提高黑白图表的可读性?
from matplotlib import pyplot

SERIES_COLORS = 'bgrcmyk'

def plot_series(xy_pairs, series, color):
    label_fmt = "{}Lock"
    x, y_lists = zip(*xy_pairs)
    normalized_ys = [[y / numpy.linalg.norm(ys) for y in ys]
                     for ys in y_lists]

    y = [numpy.average(y_list) for i, y_list
         in enumerate(normalized_ys)]
    y_err = [numpy.std(y_list) for i, y_list in
             enumerate(normalized_ys)]

    pyplot.errorbar(x, y, y_err,
                    label=label_fmt.format(series),
                    fmt='{}o-'.format(color)
                    ls='-')


def main():
    big_dataset = {
        'a': data_for_a,
        'b': data_for_b,
        'c': data_for_c,.
        ....
    }

    for series, color in zip(SERIES_COLORS, big_dataset):
        processed = do_work(big_dataset[series])

        plot_series(processed, series, color)

    pyplot.show()
1个回答

3
你可以尝试使用不同的线条样式和标记来制图。
这是一个很好的例子,摘自http://matplotlib.org/examples/pylab_examples/line_styles.html
#!/usr/bin/env python
# This should probably be replaced with a demo that shows all
# line and marker types in a single panel, with labels.

import matplotlib.pyplot as plt
from matplotlib.lines import Line2D
import numpy as np

t = np.arange(0.0, 1.0, 0.1)
s = np.sin(2*np.pi*t)
linestyles = ['_', '-', '--', ':']
markers = []
for m in Line2D.markers:
    try:
        if len(m) == 1 and m != ' ':
            markers.append(m)
    except TypeError:
        pass

styles = markers + [
    r'$\lambda$',
    r'$\bowtie$',
    r'$\circlearrowleft$',
    r'$\clubsuit$',
    r'$\checkmark$']

colors = ('b', 'g', 'r', 'c', 'm', 'y', 'k')

plt.figure(figsize=(8,8))

axisNum = 0
for row in range(6):
    for col in range(5):
        axisNum += 1
        ax = plt.subplot(6, 5, axisNum)
        color = colors[axisNum % len(colors)]
        if axisNum < len(linestyles):
            plt.plot(t, s, linestyles[axisNum], color=color, markersize=10)
        else:
            style = styles[(axisNum - len(linestyles)) % len(styles)]
            plt.plot(t, s, linestyle='None', marker=style, color=color, markersize=10)
        ax.set_yticklabels([])
        ax.set_xticklabels([])

plt.show()

你也可以将它们全部组合在一起。
x = linspace(0,1,10)
ls = ["-","--","-."]
markers = ["o","s","d"]
clrs = ["k"]
k = 1

for l in ls:
    for m in markers:
        for c in clrs:
            plot(x,x**k,m+l+c)
            k+=1

希望这有所帮助。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接