Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitae2a558

Browse files
committed
Corrected errors in pytest
Made it flake8 compliant
1 parentccaffe2 commitae2a558

File tree

3 files changed

+42
-33
lines changed

3 files changed

+42
-33
lines changed

‎lib/matplotlib/font_manager.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,7 @@ def __init__(self,
695695
self._stretch=rcParams['font.stretch']
696696
self._size=rcParams['font.size']
697697
self._file=None
698+
self._mathtext_fontset=rcParams['mathtext.fontset']
698699

699700
ifisinstance(family,str):
700701
# Treat family as a fontconfig pattern if it is the only
@@ -822,7 +823,7 @@ def get_fontconfig_pattern(self):
822823

823824
defget_mathtext_fontset(self):
824825
"""
825-
Return the mathtext_fontset being used for this object.
826+
Returns the mathtext_fontset being used for this object.
826827
827828
See Also
828829
--------
@@ -947,7 +948,12 @@ def set_mathtext_fontset(self, fontset):
947948
"""
948949
The mathtext_fontset is the family of fonts used in case this text is
949950
rendered in math mode.
950-
951+
952+
Parameters
953+
----------
954+
fontset : str, the name of the fontset. Available fontsets are defined
955+
in the matplotlibrc.template file
956+
951957
See Also
952958
--------
953959
.text.set_mathtext_fontset
@@ -958,7 +964,7 @@ def set_mathtext_fontset(self, fontset):
958964
#this function validates the parameter fontset just as if it were
959965
#passed to rcParams['mathtext.fontset']
960966
_validators['mathtext.fontset'](fontset)
961-
self._mathtext_fontset=fontset
967+
self._mathtext_fontset=fontset
962968

963969
defcopy(self):
964970
"""Return a copy of self."""

‎lib/matplotlib/tests/test_mathtext.py

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -367,56 +367,55 @@ def test_mathtext_to_png(tmpdir):
367367

368368

369369
deftest_mathtext_fontset():
370-
#This is my first time doing this kinds of tests, so I am not sure if I am
370+
#This is my first time doing this kinds of tests, so I am not sure if I am
371371
#doing it the right way, here's my plan for this testing:
372372
#
373-
#1) Create two figures, one without my implementation
374-
# (should produce 2 texts with the same font)
373+
#1) Create two figures, one without my implementation
374+
# (should produce 2 texts with the same font)
375375
# and one with (should create two texts with different fonts)
376376
#2) Save the figures on Disk
377377
#3) Load the figures and compare them, if they are equal, the test fails
378-
#4) Delete the figures
378+
#4) Delete the figures
379379
#
380-
# I am making the test a bit slower but avoiding the burden of adding
380+
# I am making the test a bit slower but avoiding the burden of adding
381381
# more figures to the repo. On my computer at least, the time for this
382382
# test was of the order of a few seconds.
383-
383+
384384
plt.rcParams["mathtext.fontset"]="dejavusans"
385385

386386
#figure 1 setup
387-
#this figure IS NOT using the 'fontset' argument, therefore,
387+
#this figure IS NOT using the 'fontset' argument, therefore,
388388
#the font should be equal to the font set in rcParams["mathtext.fontset"]
389-
f1,ax1=plt.subplots(figsize=(12,10))
390-
ax1.plot(range(11),color="0.9")
391-
ax1.text(0.2,9,r"$\mathit{This\ text\ should\ have\ a\ one\ font} $",
389+
f1,ax1=plt.subplots(figsize=(12,10))
390+
ax1.plot(range(11),color="0.9")
391+
ax1.text(0.2,9,r"$\mathit{This\ text\ should\ have\ a\ one\ font} $",
392392
size=18)
393-
394-
ax1.text(0.2,8,r"$\mathit{This\ text\ should\ have\ another} $",
393+
394+
ax1.text(0.2,8,r"$\mathit{This\ text\ should\ have\ another} $",
395395
size=18)
396-
396+
397397
#figure 2 setup
398398
#this figure IS using the 'fontset' parameter and must have two texts
399399
#with distinct fonts in the final image
400-
f2,ax2=plt.subplots(figsize=(12,10))
401-
ax2.plot(range(11),color="0.9")
402-
ax2.text(0.2,9,r"$\mathit{This\ text\ should\ have\ a\ one\ font} $",
403-
size=18,fontset='dejavusans')
404-
405-
ax2.text(0.2,8,r"$\mathit{This\ text\ should\ have\ another} $",
406-
size=18,fontset='dejavuserif')
407-
400+
f2,ax2=plt.subplots(figsize=(12,10))
401+
ax2.plot(range(11),color="0.9")
402+
ax2.text(0.2,9,r"$\mathit{This\ text\ should\ have\ a\ one\ font} $",
403+
size=18,fontset='dejavusans')
404+
405+
ax2.text(0.2,8,r"$\mathit{This\ text\ should\ have\ another} $",
406+
size=18,fontset='dejavuserif')
407+
408408
f1.savefig('mathtext_fontset_image1.png')
409409
f2.savefig('mathtext_fontset_image2.png')
410-
410+
411411
figureLoaded1=io.FileIO('mathtext_fontset_image1.png').readall()
412412
figureLoaded2=io.FileIO('mathtext_fontset_image2.png').readall()
413-
413+
414414
figuresEqual=figureLoaded1==figureLoaded2
415-
415+
416416
os.remove('mathtext_fontset_image1.png')
417417
os.remove('mathtext_fontset_image2.png')
418-
418+
419419
#if the parameter fontset is not working, the figures will be equal and the
420420
#test will fail
421421
assertnotfiguresEqual
422-

‎lib/matplotlib/text.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,19 +1044,23 @@ def set_fontsize(self, fontsize):
10441044
"""
10451045
self._fontproperties.set_size(fontsize)
10461046
self.stale=True
1047-
1047+
10481048
defset_mathtext_fontset(self,fontset):
10491049
"""
1050-
The mathtext_fontset will be the fontset used in case this text
1050+
The mathtext_fontset will be the fontset used in case this text
10511051
is rendered as mathtext
10521052
1053-
The purpouse of the function is be simmilar to rcParams['mathtext.fontset']
1053+
The purpouse of the function is be simmilar to rcParams
10541054
but for each Text element instead of global.
1055-
1055+
10561056
Parameters
10571057
----------
10581058
fontset : str, the name of the fontset. Available fontsets are defined
10591059
in the matplotlibrc.template file
1060+
1061+
See also
1062+
----------
1063+
matplotlib.rcParams
10601064
"""
10611065
self._fontproperties.set_mathtext_fontset(fontset)
10621066

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp