Skip to content
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
21 changes: 14 additions & 7 deletions lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,19 @@ def get_clip_path(self):
return self._clippath.get_transformed_path_and_affine()
return None, None

@staticmethod
def scale_dashes(linewidth, offset_dashes):
"""
Scale the given offset, dashlist tuple to fit linewidth.
"""
scale = max(1.0, linewidth)
offset, dashes = offset_dashes
if offset is not None:
offset = offset * scale
if dashes is not None:
dashes = [x * scale for x in dashes]
return offset, dashes

def get_dashes(self):
"""
Return the dash information as an offset dashlist tuple.
Expand All @@ -874,13 +887,7 @@ def get_dashes(self):
if rcParams['_internal.classic_mode']:
return self._dashes
else:
scale = max(1.0, self.get_linewidth())
offset, dashes = self._dashes
if offset is not None:
offset = offset * scale
if dashes is not None:
dashes = [x * scale for x in dashes]
return offset, dashes
return self.scale_dashes(self.get_linewidth(), self._dashes)

def get_forced_alpha(self):
"""
Expand Down
27 changes: 14 additions & 13 deletions lib/matplotlib/backends/backend_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2206,15 +2206,19 @@ def capstyle_cmd(self, style):
def joinstyle_cmd(self, style):
return [self.joinstyles[style], Op.setlinejoin]

def linewidth_cmd(self, width):
return [width, Op.setlinewidth]

def dash_cmd(self, dashes):
offset, dash = dashes
if dash is None:
dash = []
offset = 0
return [list(dash), offset, Op.setdash]
def linewidth_dash_cmd(self, width, dashes):
result = []
if self.get_linewidth() != width:
result += [width, Op.setlinewidth]
if self._dashes != dashes:
offset, dash = self.scale_dashes(width, dashes)
if offset is None or dash is None:
dash = []
offset = 0
if sum(dash) > 0:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check should probably be moved up into the base class?

offset %= sum(dash)
result += [list(dash), offset, Op.setdash]
return result

def alpha_cmd(self, alpha, forced, effective_alphas):
name = self.file.alphaState(effective_alphas)
Expand Down Expand Up @@ -2288,14 +2292,11 @@ def clip_cmd(self, cliprect, clippath):
(('_capstyle',), capstyle_cmd),
(('_fillcolor',), fillcolor_cmd),
(('_joinstyle',), joinstyle_cmd),
(('_linewidth',), linewidth_cmd),
(('_dashes',), dash_cmd),
(('_linewidth', '_dashes'), linewidth_dash_cmd),
(('_rgb',), rgb_cmd),
(('_hatch',), hatch_cmd), # must come after fillcolor and rgb
)

# TODO: _linestyle

def delta(self, other):
"""
Copy properties of other into self and return PDF commands
Expand Down
Binary file modified lib/matplotlib/tests/baseline_images/test_axes/dash_offset.pdf
Binary file not shown.
Binary file modified lib/matplotlib/tests/baseline_images/test_axes/step_linestyle.pdf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified lib/matplotlib/tests/baseline_images/test_image/rotate_image.pdf
Binary file not shown.
Binary file modified lib/matplotlib/tests/baseline_images/test_lines/line_dashes.pdf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.