Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 83fa71f

Browse filesBrowse files
authored
Merge pull request #9125 from anntzer/cleanup
MNT: rcparam keys always exist in rcparams dict
2 parents 4f73376 + 8d71309 commit 83fa71f
Copy full SHA for 83fa71f

File tree

Expand file treeCollapse file tree

3 files changed

+75
-86
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+75
-86
lines changed

‎lib/matplotlib/backends/backend_agg.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_agg.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ def print_jpg(self, filename_or_obj, *args, **kwargs):
569569
# The image is "pasted" onto a white background image to safely
570570
# handle any transparency
571571
image = Image.frombuffer('RGBA', size, buf, 'raw', 'RGBA', 0, 1)
572-
rgba = mcolors.to_rgba(rcParams.get('savefig.facecolor', 'white'))
572+
rgba = mcolors.to_rgba(rcParams['savefig.facecolor'])
573573
color = tuple([int(x * 255.0) for x in rgba[:3]])
574574
background = Image.new('RGB', size, color)
575575
background.paste(image, image)

‎lib/matplotlib/backends/backend_pgf.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_pgf.py
+9-11Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
def get_texcommand():
5757
"""Get chosen TeX system from rc."""
5858
texsystem_options = ["xelatex", "lualatex", "pdflatex"]
59-
texsystem = rcParams.get("pgf.texsystem", "xelatex")
59+
texsystem = rcParams["pgf.texsystem"]
6060
return texsystem if texsystem in texsystem_options else "xelatex"
6161

6262

@@ -68,7 +68,7 @@ def get_fontspec():
6868
if texcommand != "pdflatex":
6969
latex_fontspec.append("\\usepackage{fontspec}")
7070

71-
if texcommand != "pdflatex" and rcParams.get("pgf.rcfonts", True):
71+
if texcommand != "pdflatex" and rcParams["pgf.rcfonts"]:
7272
# try to find fonts from rc parameters
7373
families = ["serif", "sans-serif", "monospace"]
7474
fontspecs = [r"\setmainfont{%s}", r"\setsansfont{%s}",
@@ -86,10 +86,7 @@ def get_fontspec():
8686

8787
def get_preamble():
8888
"""Get LaTeX preamble from rc."""
89-
latex_preamble = rcParams.get("pgf.preamble", "")
90-
if type(latex_preamble) == list:
91-
latex_preamble = "\n".join(latex_preamble)
92-
return latex_preamble
89+
return "\n".join(rcParams["pgf.preamble"])
9390

9491
###############################################################################
9592

@@ -223,13 +220,14 @@ def get_latex_manager():
223220
latex_header = LatexManager._build_latex_header()
224221
prev = LatexManagerFactory.previous_instance
225222

226-
# check if the previous instance of LatexManager can be reused
227-
if prev and prev.latex_header == latex_header and prev.texcommand == texcommand:
228-
if rcParams.get("pgf.debug", False):
223+
# Check if the previous instance of LatexManager can be reused.
224+
if (prev and prev.latex_header == latex_header
225+
and prev.texcommand == texcommand):
226+
if rcParams["pgf.debug"]:
229227
print("reusing LatexManager")
230228
return prev
231229
else:
232-
if rcParams.get("pgf.debug", False):
230+
if rcParams["pgf.debug"]:
233231
print("creating LatexManager")
234232
new_inst = LatexManager()
235233
LatexManagerFactory.previous_instance = new_inst
@@ -289,7 +287,7 @@ def __init__(self):
289287
# store references for __del__
290288
self._os_path = os.path
291289
self._shutil = shutil
292-
self._debug = rcParams.get("pgf.debug", False)
290+
self._debug = rcParams["pgf.debug"]
293291

294292
# create a tmp directory for running latex, remember to cleanup
295293
self.tmpdir = tempfile.mkdtemp(prefix="mpl_pgf_lm_")

‎lib/mpl_toolkits/mplot3d/axis3d.py

Copy file name to clipboardExpand all lines: lib/mpl_toolkits/mplot3d/axis3d.py
+65-74Lines changed: 65 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
import math
1111
import copy
1212

13-
from matplotlib import lines as mlines, axis as maxis, \
14-
patches as mpatches
13+
from matplotlib import lines as mlines, axis as maxis, patches as mpatches
1514
from matplotlib import rcParams
1615
from . import art3d
1716
from . import proj3d
@@ -40,8 +39,8 @@ def move_from_center(coord, centers, deltas, axmask=(True, True, True)):
4039
def tick_update_position(tick, tickxs, tickys, labelpos):
4140
'''Update tick line and label position and style.'''
4241

43-
for (label, on) in ((tick.label1, tick.label1On), \
44-
(tick.label2, tick.label2On)):
42+
for (label, on) in [(tick.label1, tick.label1On),
43+
(tick.label2, tick.label2On)]:
4544
if on:
4645
label.set_position(labelpos)
4746

@@ -81,68 +80,57 @@ def __init__(self, adir, v_intervalx, d_intervalx, axes, *args, **kwargs):
8180
# Do not depend on this existing in future releases!
8281
self._axinfo = self._AXINFO[adir].copy()
8382
if rcParams['_internal.classic_mode']:
84-
self._axinfo.update({'label':
85-
{'va': 'center',
86-
'ha': 'center'},
87-
'tick':
88-
{'inward_factor': 0.2,
89-
'outward_factor': 0.1,
90-
'linewidth': rcParams['lines.linewidth'],
91-
'color': 'k'},
92-
'axisline':
93-
{'linewidth': 0.75,
94-
'color': (0, 0, 0, 1)},
95-
'grid' :
96-
{'color': (0.9, 0.9, 0.9, 1),
97-
'linewidth': 1.0,
98-
'linestyle': '-'},
99-
})
83+
self._axinfo.update(
84+
{'label': {'va': 'center',
85+
'ha': 'center'},
86+
'tick': {'inward_factor': 0.2,
87+
'outward_factor': 0.1,
88+
'linewidth': rcParams['lines.linewidth'],
89+
'color': 'k'},
90+
'axisline': {'linewidth': 0.75,
91+
'color': (0, 0, 0, 1)},
92+
'grid': {'color': (0.9, 0.9, 0.9, 1),
93+
'linewidth': 1.0,
94+
'linestyle': '-'},
95+
})
10096
else:
101-
self._axinfo.update({'label' :
102-
{'va': 'center',
103-
'ha': 'center'},
104-
'tick' :
105-
{'inward_factor': 0.2,
106-
'outward_factor': 0.1,
107-
'linewidth': rcParams.get(
108-
adir + 'tick.major.width',
109-
rcParams['xtick.major.width']),
110-
'color': rcParams.get(
111-
adir + 'tick.color',
112-
rcParams['xtick.color'])},
113-
'axisline':
114-
{'linewidth': rcParams['axes.linewidth'],
115-
'color': rcParams['axes.edgecolor']},
116-
'grid' :
117-
{'color': rcParams['grid.color'],
118-
'linewidth': rcParams['grid.linewidth'],
119-
'linestyle': rcParams['grid.linestyle']},
120-
})
121-
97+
self._axinfo.update(
98+
{'label': {'va': 'center',
99+
'ha': 'center'},
100+
'tick': {'inward_factor': 0.2,
101+
'outward_factor': 0.1,
102+
'linewidth': rcParams.get(
103+
adir + 'tick.major.width',
104+
rcParams['xtick.major.width']),
105+
'color': rcParams.get(
106+
adir + 'tick.color',
107+
rcParams['xtick.color'])},
108+
'axisline': {'linewidth': rcParams['axes.linewidth'],
109+
'color': rcParams['axes.edgecolor']},
110+
'grid': {'color': rcParams['grid.color'],
111+
'linewidth': rcParams['grid.linewidth'],
112+
'linestyle': rcParams['grid.linestyle']},
113+
})
122114

123115
maxis.XAxis.__init__(self, axes, *args, **kwargs)
124-
125116
self.set_rotate_label(kwargs.get('rotate_label', None))
126117

127-
128118
def init3d(self):
129-
self.line = mlines.Line2D(xdata=(0, 0), ydata=(0, 0),
130-
linewidth=self._axinfo['axisline']['linewidth'],
131-
color=self._axinfo['axisline']['color'],
132-
antialiased=True,
133-
)
119+
self.line = mlines.Line2D(
120+
xdata=(0, 0), ydata=(0, 0),
121+
linewidth=self._axinfo['axisline']['linewidth'],
122+
color=self._axinfo['axisline']['color'],
123+
antialiased=True)
134124

135125
# Store dummy data in Polygon object
136-
self.pane = mpatches.Polygon(np.array([[0,0], [0,1], [1,0], [0,0]]),
137-
closed=False,
138-
alpha=0.8,
139-
facecolor=(1,1,1,0),
140-
edgecolor=(1,1,1,0))
126+
self.pane = mpatches.Polygon(
127+
np.array([[0, 0], [0, 1], [1, 0], [0, 0]]),
128+
closed=False, alpha=0.8, facecolor='k', edgecolor='k')
141129
self.set_pane_color(self._axinfo['color'])
142130

143131
self.axes._set_artist_props(self.line)
144132
self.axes._set_artist_props(self.pane)
145-
self.gridlines = art3d.Line3DCollection([], )
133+
self.gridlines = art3d.Line3DCollection([])
146134
self.axes._set_artist_props(self.gridlines)
147135
self.axes._set_artist_props(self.label)
148136
self.axes._set_artist_props(self.offsetText)
@@ -153,7 +141,8 @@ def init3d(self):
153141
def get_tick_positions(self):
154142
majorLocs = self.major.locator()
155143
self.major.formatter.set_locs(majorLocs)
156-
majorLabels = [self.major.formatter(val, i) for i, val in enumerate(majorLocs)]
144+
majorLabels = [self.major.formatter(val, i)
145+
for i, val in enumerate(majorLocs)]
157146
return majorLabels, majorLocs
158147

159148
def get_major_ticks(self, numticks=None):
@@ -173,7 +162,7 @@ def set_pane_pos(self, xys):
173162
self.stale = True
174163

175164
def set_pane_color(self, color):
176-
'''Set pane color to a RGBA tuple'''
165+
'''Set pane color to a RGBA tuple.'''
177166
self._axinfo['color'] = color
178167
self.pane.set_edgecolor(color)
179168
self.pane.set_facecolor(color)
@@ -211,8 +200,8 @@ def _get_coord_info(self, renderer):
211200

212201
vals = mins[0], maxs[0], mins[1], maxs[1], mins[2], maxs[2]
213202
tc = self.axes.tunit_cube(vals, renderer.M)
214-
avgz = [tc[p1][2] + tc[p2][2] + tc[p3][2] + tc[p4][2] for \
215-
p1, p2, p3, p4 in self._PLANES]
203+
avgz = [tc[p1][2] + tc[p2][2] + tc[p3][2] + tc[p4][2]
204+
for p1, p2, p3, p4 in self._PLANES]
216205
highs = np.array([avgz[2*i] < avgz[2*i+1] for i in range(3)])
217206

218207
return mins, maxs, centers, deltas, tc, highs
@@ -301,13 +290,13 @@ def draw(self, renderer):
301290
ax_points_estimate = sum(72. * ax_inches)
302291
deltas_per_point = 48. / ax_points_estimate
303292
default_offset = 21.
304-
labeldeltas = (self.labelpad + default_offset) * deltas_per_point\
305-
* deltas
293+
labeldeltas = (
294+
(self.labelpad + default_offset) * deltas_per_point * deltas)
306295
axmask = [True, True, True]
307296
axmask[index] = False
308297
lxyz = move_from_center(lxyz, centers, labeldeltas, axmask)
309-
tlx, tly, tlz = proj3d.proj_transform(lxyz[0], lxyz[1], lxyz[2], \
310-
renderer.M)
298+
tlx, tly, tlz = proj3d.proj_transform(lxyz[0], lxyz[1], lxyz[2],
299+
renderer.M)
311300
self.label.set_position((tlx, tly))
312301
if self.get_rotate_label(self.label.get_text()):
313302
angle = art3d.norm_text_angle(math.degrees(math.atan2(dy, dx)))
@@ -425,26 +414,28 @@ def draw(self, renderer):
425414
# Get tick line positions
426415
pos = copy.copy(edgep1)
427416
pos[index] = loc
428-
pos[tickdir] = edgep1[tickdir] + info['tick']['outward_factor'] * \
429-
ticksign * tickdelta
430-
x1, y1, z1 = proj3d.proj_transform(pos[0], pos[1], pos[2], \
431-
renderer.M)
432-
pos[tickdir] = edgep1[tickdir] - info['tick']['inward_factor'] * \
433-
ticksign * tickdelta
434-
x2, y2, z2 = proj3d.proj_transform(pos[0], pos[1], pos[2], \
435-
renderer.M)
417+
pos[tickdir] = (
418+
edgep1[tickdir]
419+
+ info['tick']['outward_factor'] * ticksign * tickdelta)
420+
x1, y1, z1 = proj3d.proj_transform(pos[0], pos[1], pos[2],
421+
renderer.M)
422+
pos[tickdir] = (
423+
edgep1[tickdir]
424+
- info['tick']['inward_factor'] * ticksign * tickdelta)
425+
x2, y2, z2 = proj3d.proj_transform(pos[0], pos[1], pos[2],
426+
renderer.M)
436427

437428
# Get position of label
438429
default_offset = 8. # A rough estimate
439-
labeldeltas = (tick.get_pad() + default_offset) * deltas_per_point\
440-
* deltas
430+
labeldeltas = (
431+
(tick.get_pad() + default_offset) * deltas_per_point * deltas)
441432

442433
axmask = [True, True, True]
443434
axmask[index] = False
444435
pos[tickdir] = edgep1[tickdir]
445436
pos = move_from_center(pos, centers, labeldeltas, axmask)
446-
lx, ly, lz = proj3d.proj_transform(pos[0], pos[1], pos[2], \
447-
renderer.M)
437+
lx, ly, lz = proj3d.proj_transform(pos[0], pos[1], pos[2],
438+
renderer.M)
448439

449440
tick_update_position(tick, (x1, x2), (y1, y2), (lx, ly))
450441
tick.tick1line.set_linewidth(info['tick']['linewidth'])

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.