美文网首页
Linestyles

Linestyles

作者: 榴莲气象 | 来源:发表于2019-06-12 19:59 被阅读0次

https://matplotlib.org/3.1.0/gallery/lines_bars_and_markers/linestyles.html

from matplotlib import lines
lines.lineStyles.keys()

['', ' ', 'None', '--', '-.', '-', ':']

You can copy the dictionary from the Linestyle example:

from collections import OrderedDict

linestyles = OrderedDict(
    [('solid',               (0, ())),
     ('loosely dotted',      (0, (1, 10))),
     ('dotted',              (0, (1, 5))),
     ('densely dotted',      (0, (1, 1))),

     ('loosely dashed',      (0, (5, 10))),
     ('dashed',              (0, (5, 5))),
     ('densely dashed',      (0, (5, 1))),

     ('loosely dashdotted',  (0, (3, 10, 1, 10))),
     ('dashdotted',          (0, (3, 5, 1, 5))),
     ('densely dashdotted',  (0, (3, 1, 1, 1))),

     ('loosely dashdotdotted', (0, (3, 10, 1, 10, 1, 10))),
     ('dashdotdotted',         (0, (3, 5, 1, 5, 1, 5))),
     ('densely dashdotdotted', (0, (3, 1, 1, 1, 1, 1)))])

You can then iterate over the linestyles

fig, ax = plt.subplots()

X, Y = np.linspace(0, 100, 10), np.zeros(10)
for i, (name, linestyle) in enumerate(linestyles.items()):
    ax.plot(X, Y+i, linestyle=linestyle, linewidth=1.5, color='black')

ax.set_ylim(-0.5, len(linestyles)-0.5)

plt.show()

Or you just take a single linestyle out of those,

ax.plot([0,100], [0,1], linestyle=linestyles['loosely dashdotdotted'])

相关文章

  • Linestyles

    https://matplotlib.org/3.1.0/gallery/lines_bars_and_marke...

网友评论

      本文标题:Linestyles

      本文链接:https://www.haomeiwen.com/subject/hkurfctx.html