import numpy as np
import matplotlib.pyplot as plt

linestyle_str = [
     ('solid', 'solid'),      # Same as (0, ()) or '-'
     ('dotted', 'dotted'),    # Same as (0, (1, 1)) or '.'
     ('dashed', 'dashed'),    # Same as '--'
     ('dashdot', 'dashdot')]  # Same as '-.'

linestyle_tuple = [
     ('loosely dotted',        (0, (1, 10))),
     ('dotted',                (0, (1, 1))),
     ('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))),

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


def plot_linestyles(ax, linestyles):
    X, Y = np.linspace(0, 100, 10), np.zeros(10)
    yticklabels = []

    for i, (name, linestyle) in enumerate(linestyles):
        ax.plot(X, Y+i, linestyle=linestyle, linewidth=1.5, color='black')
        yticklabels.append(name)

    ax.set(xticks=[], ylim=(-0.5, len(linestyles)-0.5),
           yticks=np.arange(len(linestyles)), yticklabels=yticklabels)

    # For each line style, add a text annotation with a small offset from
    # the reference point (0 in Axes coords, y tick value in Data coords).
    for i, (name, linestyle) in enumerate(linestyles):
        ax.annotate(repr(linestyle),
                    xy=(0.0, i), xycoords=ax.get_yaxis_transform(),
                    xytext=(-6, -12), textcoords='offset points',
                    color="blue", fontsize=8, ha="right", family="monospace")


fig, (ax0, ax1) = plt.subplots(2, 1, gridspec_kw={'height_ratios': [1, 3]},
                               figsize=(10, 8))

plot_linestyles(ax0, linestyle_str[::-1])
plot_linestyles(ax1, linestyle_tuple[::-1])

plt.tight_layout()
plt.show()

 

python matplotlib 绘图线条类型和颜色选择_html

 

 

python matplotlib 绘图线条类型和颜色选择_html_02

 

 

REF

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

The following format string characters are accepted to control the line style or marker:

character

description

'-'

solid line style

'--'

dashed line style

'-.'

dash-dot line style

':'

dotted line style

'.'

point marker

','

pixel marker

'o'

circle marker

'v'

triangle_down marker

'^'

triangle_up marker

'<'

triangle_left marker

'>'

triangle_right marker

'1'

tri_down marker

'2'

tri_up marker

'3'

tri_left marker

'4'

tri_right marker

's'

square marker

'p'

pentagon marker

'*'

star marker

'h'

hexagon1 marker

'H'

hexagon2 marker

'+'

plus marker

'x'

x marker

'D'

diamond marker

'd'

thin_diamond marker

'|'

vline marker

'_'

hline marker

The following color abbreviations are supported:

character

color

‘b’

blue

‘g’

green

‘r’

red

‘c’

cyan

‘m’

magenta

‘y’

yellow

‘k’

black

‘w’

white

 

 

REF

good demos

https://matplotlib.org/2.1.1/api/_as_gen/matplotlib.pyplot.plot.html

All possible markers are defined here:

marker

symbol

description

"."

python matplotlib 绘图线条类型和颜色选择_ide_03

point

","

python matplotlib 绘图线条类型和颜色选择_html_04

pixel

"o"

python matplotlib 绘图线条类型和颜色选择_ci_05

circle

"v"

python matplotlib 绘图线条类型和颜色选择_ci_06

triangle_down

"^"

python matplotlib 绘图线条类型和颜色选择_html_07

triangle_up

"<"

python matplotlib 绘图线条类型和颜色选择_ide_08

triangle_left

">"

python matplotlib 绘图线条类型和颜色选择_html_09

triangle_right

"1"

python matplotlib 绘图线条类型和颜色选择_ide_10

tri_down

"2"

python matplotlib 绘图线条类型和颜色选择_html_11

tri_up

"3"

python matplotlib 绘图线条类型和颜色选择_html_12

tri_left

"4"

python matplotlib 绘图线条类型和颜色选择_ide_13

tri_right

"8"

python matplotlib 绘图线条类型和颜色选择_ci_14

octagon

"s"

python matplotlib 绘图线条类型和颜色选择_ide_15

square

"p"

python matplotlib 绘图线条类型和颜色选择_ci_16

pentagon

"P"

python matplotlib 绘图线条类型和颜色选择_ide_17

plus (filled)

"*"

python matplotlib 绘图线条类型和颜色选择_ci_18

star

"h"

python matplotlib 绘图线条类型和颜色选择_ide_19

hexagon1

"H"

python matplotlib 绘图线条类型和颜色选择_html_20

hexagon2

"+"

python matplotlib 绘图线条类型和颜色选择_ide_21

plus

"x"

python matplotlib 绘图线条类型和颜色选择_ide_22

x

"X"

python matplotlib 绘图线条类型和颜色选择_ide_23

x (filled)

"D"

python matplotlib 绘图线条类型和颜色选择_ci_24

diamond

"d"

python matplotlib 绘图线条类型和颜色选择_ide_25

thin_diamond

"|"

python matplotlib 绘图线条类型和颜色选择_ci_26

vline

"_"

python matplotlib 绘图线条类型和颜色选择_ci_27

hline

0 (TICKLEFT)

python matplotlib 绘图线条类型和颜色选择_ci_28

tickleft

1 (TICKRIGHT)

python matplotlib 绘图线条类型和颜色选择_ide_29

tickright

2 (TICKUP)

python matplotlib 绘图线条类型和颜色选择_ide_30

tickup

3 (TICKDOWN)

python matplotlib 绘图线条类型和颜色选择_html_31

tickdown

4 (CARETLEFT)

python matplotlib 绘图线条类型和颜色选择_html_32

caretleft

5 (CARETRIGHT)

python matplotlib 绘图线条类型和颜色选择_html_33

caretright

6 (CARETUP)

python matplotlib 绘图线条类型和颜色选择_ide_34

caretup

7 (CARETDOWN)

python matplotlib 绘图线条类型和颜色选择_html_35

caretdown

8 (CARETLEFTBASE)

python matplotlib 绘图线条类型和颜色选择_ci_36

caretleft (centered at base)

9 (CARETRIGHTBASE)

python matplotlib 绘图线条类型和颜色选择_ci_37

caretright (centered at base)

10 (CARETUPBASE)

python matplotlib 绘图线条类型和颜色选择_ci_38

caretup (centered at base)

11 (CARETDOWNBASE)

python matplotlib 绘图线条类型和颜色选择_html_39

caretdown (centered at base)

"None"" " or ""

 

nothing

'$...$'

python matplotlib 绘图线条类型和颜色选择_ide_40

Render the string using mathtext. E.g "$f$" for marker showing the letter f.

verts

 

A list of (x, y) pairs used for Path vertices. The center of the marker is located at (0,0) and the size is normalized, such that the created path is encapsulated inside the unit cell.

path

 

Path instance.

(numsides, style, angle)

 

The marker can also be a tuple (numsides, style, angle), which will create a custom, regular symbol.

numsides:

the number of sidesstyle:

the style of the regular symbol:

  • 0: a regular polygon
  • 1: a star-like symbol
  • 2: an asterisk
  • 3: a circle (numsides and angle is ignored); deprecated.

angle:

the angle of rotation of the symbol

 

REF

https://matplotlib.org/3.1.0/api/markers_api.html

 

 

 

python matplotlib 绘图线条类型和颜色选择_ide_41

 

 

 

REF

https://matplotlib.org/stable/tutorials/colors/colors.html

https://matplotlib.org/stable/gallery/color/named_colors.html