Skip to content

[WiP] ENH: Add a “loose” version of the dashed line styles #8048

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,24 @@ def _process_plot_format(fmt):

# handle the multi char special cases and strip them from the
# string
if fmt.find('--') >= 0:
if fmt.find('--@loose') >= 0:
linestyle = '--@loose'
fmt = fmt.replace('--@loose', '')
elif fmt.find('--') >= 0:
linestyle = '--'
fmt = fmt.replace('--', '')
if fmt.find('-.') >= 0:

if fmt.find('-.@loose') >= 0:
linestyle = '-.@loose'
fmt = fmt.replace('-.@loose', '')
elif fmt.find('-.') >= 0:
linestyle = '-.'
fmt = fmt.replace('-.', '')

if fmt.find(':@loose') >= 0:
linestyle = ':@loose'
fmt = fmt.replace(':@loose', '')

if fmt.find(' ') >= 0:
linestyle = 'None'
fmt = fmt.replace(' ', '')
Expand Down
4 changes: 3 additions & 1 deletion lib/matplotlib/cbook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1896,7 +1896,9 @@ def unmasked_index_ranges(mask, compressed=True):

# The ls_mapper maps short codes for line style to their full name used by
# backends; the reverse mapper is for mapping full names to short ones.
ls_mapper = {'-': 'solid', '--': 'dashed', '-.': 'dashdot', ':': 'dotted'}
ls_mapper = {'-': 'solid', '--': 'dashed', '-.': 'dashdot', ':': 'dotted',
'--@loose': 'dashed@loose', '-.@loose': 'dashdot@loose',
':@loose': 'dotted@loose'}
ls_mapper_r = {v: k for k, v in six.iteritems(ls_mapper)}


Expand Down
38 changes: 29 additions & 9 deletions lib/matplotlib/lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def _get_dash_pattern(style):
if style in ['solid', 'None']:
offset, dashes = None, None
# dashed styles
elif style in ['dashed', 'dashdot', 'dotted']:
elif style in ['dashed', 'dashdot', 'dotted', 'dashed@loose',
'dashdot@loose', 'dotted@loose']:
offset = 0
dashes = tuple(rcParams['lines.{}_pattern'.format(style)])
#
Expand Down Expand Up @@ -239,13 +240,16 @@ class Line2D(Artist):

"""
lineStyles = _lineStyles = { # hidden names deprecated
'-': '_draw_solid',
'--': '_draw_dashed',
'-.': '_draw_dash_dot',
':': '_draw_dotted',
'None': '_draw_nothing',
' ': '_draw_nothing',
'': '_draw_nothing',
'-': '_draw_solid',
'--': '_draw_dashed',
'-.': '_draw_dash_dot',
':': '_draw_dotted',
'None': '_draw_nothing',
' ': '_draw_nothing',
'': '_draw_nothing',
'--@loose': '_draw_dashed_loose',
'-.@loose': '_draw_dash_dot_loose',
':@loose': '_draw_dotted_loose',
}

_drawStyles_l = {
Expand Down Expand Up @@ -1262,6 +1266,21 @@ def _draw_dotted(self, renderer, gc, path, trans):
gc.set_dashes(self._dashOffset, self._dashSeq)
renderer.draw_path(gc, path, trans)

def _draw_dashed_loose(self, renderer, gc, path, trans):
gc.set_linestyle('dashed@loose')
gc.set_dashes(self._dashOffset, self._dashSeq)
renderer.draw_path(gc, path, trans)

def _draw_dash_dot_loose(self, renderer, gc, path, trans):
gc.set_linestyle('dashdot@loose')
gc.set_dashes(self._dashOffset, self._dashSeq)
renderer.draw_path(gc, path, trans)

def _draw_dotted_loose(self, renderer, gc, path, trans):
gc.set_linestyle('dotted@loose')
gc.set_dashes(self._dashOffset, self._dashSeq)
renderer.draw_path(gc, path, trans)

def update_from(self, other):
"""copy properties from other to self"""
Artist.update_from(self, other)
Expand Down Expand Up @@ -1452,7 +1471,8 @@ def get_solid_capstyle(self):

def is_dashed(self):
'return True if line is dashstyle'
return self._linestyle in ('--', '-.', ':')
return self._linestyle in ('--', '-.', ':', '--@loose', '-.@loose',
':@loose')


class VertexSelector(object):
Expand Down
4 changes: 4 additions & 0 deletions lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,10 @@ def validate_animation_writer_path(p):
'lines.dashed_pattern': [[2.8, 1.2], validate_nseq_float()],
'lines.dashdot_pattern': [[4.8, 1.2, 0.8, 1.2], validate_nseq_float()],
'lines.dotted_pattern': [[1.1, 1.1], validate_nseq_float()],
'lines.dashed@loose_pattern': [[2.8, 3.6], validate_nseq_float()],
'lines.dashdot@loose_pattern': [[4.8, 3.6, 0.8, 3.6],
validate_nseq_float()],
'lines.dotted@loose_pattern': [[1.1, 3.3], validate_nseq_float()],
'lines.scale_dashes': [True, validate_bool],

# marker props
Expand Down
3 changes: 3 additions & 0 deletions matplotlibrc.template
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ backend : $TEMPLATE_BACKEND
#lines.dashed_pattern : 2.8, 1.2
#lines.dashdot_pattern : 4.8, 1.2, 0.8, 1.2
#lines.dotted_pattern : 1.1, 1.1
#lines.dashed@loose_pattern : 2.8, 3.6
#lines.dashdot@loose_pattern : 4.8, 3.6, 0.8, 3.6
#lines.dotted@loose_pattern : 1.1, 3.3
#lines.scale_dashes : True

#markers.fillstyle: full # full|left|right|bottom|top|none
Expand Down