Process a MATLAB style color/line style format string. Return a (*linestyle*, *color*) tuple as a result of the processing. Default values are ('-', 'b'). Example format strings include: * 'ko': black circles * '.b': blue dots * 'r--': red dashed lines * 'C2--': the
(fmt)
| 37 | |
| 38 | |
| 39 | def _process_plot_format(fmt): |
| 40 | """ |
| 41 | Process a MATLAB style color/line style format string. Return a |
| 42 | (*linestyle*, *color*) tuple as a result of the processing. Default |
| 43 | values are ('-', 'b'). Example format strings include: |
| 44 | |
| 45 | * 'ko': black circles |
| 46 | * '.b': blue dots |
| 47 | * 'r--': red dashed lines |
| 48 | * 'C2--': the third color in the color cycle, dashed lines |
| 49 | |
| 50 | .. seealso:: |
| 51 | |
| 52 | :func:`~matplotlib.Line2D.lineStyles` and |
| 53 | :attr:`~matplotlib.colors.cnames` |
| 54 | for all possible styles and color format string. |
| 55 | """ |
| 56 | |
| 57 | linestyle = None |
| 58 | marker = None |
| 59 | color = None |
| 60 | |
| 61 | # Is fmt just a colorspec? |
| 62 | try: |
| 63 | color = mcolors.to_rgba(fmt) |
| 64 | |
| 65 | # We need to differentiate grayscale '1.0' from tri_down marker '1' |
| 66 | try: |
| 67 | fmtint = str(int(fmt)) |
| 68 | except ValueError: |
| 69 | return linestyle, marker, color # Yes |
| 70 | else: |
| 71 | if fmt != fmtint: |
| 72 | # user definitely doesn't want tri_down marker |
| 73 | return linestyle, marker, color # Yes |
| 74 | else: |
| 75 | # ignore converted color |
| 76 | color = None |
| 77 | except ValueError: |
| 78 | pass # No, not just a color. |
| 79 | |
| 80 | # handle the multi char special cases and strip them from the |
| 81 | # string |
| 82 | if fmt.find('--') >= 0: |
| 83 | linestyle = '--' |
| 84 | fmt = fmt.replace('--', '') |
| 85 | if fmt.find('-.') >= 0: |
| 86 | linestyle = '-.' |
| 87 | fmt = fmt.replace('-.', '') |
| 88 | if fmt.find(' ') >= 0: |
| 89 | linestyle = 'None' |
| 90 | fmt = fmt.replace(' ', '') |
| 91 | |
| 92 | chars = [c for c in fmt] |
| 93 | |
| 94 | i = 0 |
| 95 | while i < len(chars): |
| 96 | c = chars[i] |
no test coverage detected