python - matplotlib 中清晰易读的灰度线图?

标签 python printing graph charts matplotlib

我是一名计算机科学专业的本科生。对于我的大部分类(class),我必须制作某种图表来显示我的结果。我的大多数教授都希望将这些图表打印出来(或者,如果他们接受 PDF,他们会继续自己打印一份副本)以便对其进行评分。我将 matplotlib 与其他一些工具结合使用来生成图表,效果很好。

但是,我的问题是,我打印出的(彩色)折线图往往无法破译。举一个相对温和的例子:

enter image description here

一个更糟糕的例子(可能更多的是我设计的图表本身的问题)是:

enter image description here

当以黑白打印时,系列变得无法区分。

下面是我可能用来生成图表的脚本之一示例。我真的很想找到一种方法来制作在黑白打印机上打印时看起来尽可能清晰的图表——我该怎么做呢?哪些技术对于提高黑白图表和图形的可读性最有效?

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()

最佳答案

您可以使用不同的线条样式和标记。

这是一个很好的例子,取自 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

希望对您有所帮助。

关于python - matplotlib 中清晰易读的灰度线图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22242032/

相关文章:

python - 哪个是执行命令的最佳 python 模块

android - 需要 stariosdk getport 失败建议

graph - Neoclipse 的替代品

c++ - SPOJ - 主要路径 (PPATH)

python - 在 Pandas 中用自身的功能替换列?

python - 自动检查并从 CloudFormation 模板中删除资源 #20611

python - 空白和选择器

java - 在Java中打印表格

CSS 在打印时隐藏占位符

c# - 来自邻接列表的 JSON?