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

TST: Use text placeholders for empty legends#29908

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
tacaswell merged 1 commit intomatplotlib:mainfromQuLogic:legend-placeholders
Apr 17, 2025
Merged
Show file tree
Hide file tree
Changes fromall 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
Binary file modifiedlib/matplotlib/tests/baseline_images/test_axes/stem.png
View file
Open in desktop
Loading
Sorry, something went wrong.Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View file
Open in desktop
Binary file not shown.
View file
Open in desktop
Binary file not shown.
View file
Open in desktop
Loading
Sorry, something went wrong.Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1,269 changes: 900 additions & 369 deletionslib/matplotlib/tests/baseline_images/test_bbox_tight/bbox_inches_tight.svg
View file
Open in desktop
Loading
Sorry, something went wrong.Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View file
Open in desktop
Loading
Sorry, something went wrong.Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View file
Open in desktop
Loading
Sorry, something went wrong.Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 2 additions & 4 deletionslib/matplotlib/tests/test_axes.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4593,14 +4593,12 @@ def test_hist_stacked_weighted():


@image_comparison(['stem.png'],style='mpl20',remove_text=True)
deftest_stem():
deftest_stem(text_placeholders):
x=np.linspace(0.1,2*np.pi,100)

fig,ax=plt.subplots()
# Label is a single space to force a legend to be drawn, but to avoid any
# text being drawn
ax.stem(x,np.cos(x),
linefmt='C2-.',markerfmt='k+',basefmt='C1-.',label='')
linefmt='C2-.',markerfmt='k+',basefmt='C1-.',label='stem')
ax.legend()


Expand Down
6 changes: 4 additions & 2 deletionslib/matplotlib/tests/test_backend_pdf.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -296,14 +296,16 @@ def test_pdfpages_fspath():
pdf.savefig(plt.figure())


@image_comparison(['hatching_legend.pdf'])
deftest_hatching_legend():
@image_comparison(['hatching_legend.pdf'],style='mpl20')
deftest_hatching_legend(text_placeholders):
"""Test for correct hatching on patches in legend"""
fig=plt.figure(figsize=(1,2))

a=Rectangle([0,0],0,0,facecolor="green",hatch="XXXX")
b=Rectangle([0,0],0,0,facecolor="blue",hatch="XXXX")

# Verify that hatches in PDFs work after empty labels. See
# https://github.com/matplotlib/matplotlib/issues/4469
fig.legend([a,b,a,b], ["","","",""])


Expand Down
15 changes: 8 additions & 7 deletionslib/matplotlib/tests/test_bbox_tight.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,17 +11,18 @@
frommpl_toolkits.axes_grid1.inset_locatorimportinset_axes


@image_comparison(['bbox_inches_tight'],remove_text=True,
@image_comparison(['bbox_inches_tight'],remove_text=True,style='mpl20',
savefig_kwarg={'bbox_inches':'tight'})
deftest_bbox_inches_tight():
deftest_bbox_inches_tight(text_placeholders):
#: Test that a figure saved using bbox_inches='tight' is clipped correctly
data= [[66386,174296,75131,577908,32015],
[58230,381139,78045,99308,160454],
[89135,80552,152558,497981,603535],
[78415,81858,150656,193263,69638],
[139361,331509,343164,781380,52269]]

col_labels=row_labels= ['']*5
col_labels= ('Freeze','Wind','Flood','Quake','Hail')
row_labels= [f'{x} year'forxin (100,50,20,10,5)]

rows=len(data)
ind=np.arange(len(col_labels))+0.3# the x locations for the groups
Expand All@@ -31,13 +32,13 @@ def test_bbox_inches_tight():
# the bottom values for stacked bar chart
fig,ax=plt.subplots(1,1)
forrowinrange(rows):
ax.bar(ind,data[row],width,bottom=yoff,align='edge',color='b')
ax.bar(ind,data[row],width,bottom=yoff,align='edge')
yoff=yoff+data[row]
cell_text.append([''])
cell_text.append([f'{x/1000:1.1f}'forxinyoff])
plt.xticks([])
plt.xlim(0,5)
plt.legend(['']*5,loc=(1.2,0.2))
fig.legend(['']*5,bbox_to_anchor=(0,0.2),loc='lower left')
plt.legend(['1','2','3','4','5'],loc=(1.2,0.2))
fig.legend(['a','b','c','d','e'],bbox_to_anchor=(0,0.2),loc='lower left')
# Add a table at the bottom of the axes
cell_text.reverse()
plt.table(cellText=cell_text,rowLabels=row_labels,colLabels=col_labels,
Expand Down
6 changes: 3 additions & 3 deletionslib/matplotlib/tests/test_lines.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -332,13 +332,13 @@ def test_marker_as_markerstyle():


@image_comparison(['striped_line.png'],remove_text=True,style='mpl20')
deftest_striped_lines():
deftest_striped_lines(text_placeholders):
rng=np.random.default_rng(19680801)
_,ax=plt.subplots()
ax.plot(rng.uniform(size=12),color='orange',gapcolor='blue',
linestyle='--',lw=5,label='')
linestyle='--',lw=5,label='blue in orange')
ax.plot(rng.uniform(size=12),color='red',gapcolor='black',
linestyle=(0, (2,5,4,2)),lw=5,label='',alpha=0.5)
linestyle=(0, (2,5,4,2)),lw=5,label='black in red',alpha=0.5)
ax.legend(handlelength=5)


Expand Down
9 changes: 4 additions & 5 deletionslib/matplotlib/tests/test_patheffects.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -135,9 +135,8 @@ def test_collection():
'edgecolor':'blue'})


@image_comparison(['tickedstroke'],remove_text=True,extensions=['png'],
tol=0.22)# Increased tolerance due to fixed clipping.
deftest_tickedstroke():
@image_comparison(['tickedstroke.png'],remove_text=True,style='mpl20')
deftest_tickedstroke(text_placeholders):
fig, (ax1,ax2,ax3)=plt.subplots(1,3,figsize=(12,4))
path=Path.unit_circle()
patch=patches.PathPatch(path,facecolor='none',lw=2,path_effects=[
Expand All@@ -149,13 +148,13 @@ def test_tickedstroke():
ax1.set_xlim(-2,2)
ax1.set_ylim(-2,2)

ax2.plot([0,1], [0,1],label='',
ax2.plot([0,1], [0,1],label='C0',
path_effects=[path_effects.withTickedStroke(spacing=7,
angle=135)])
nx=101
x=np.linspace(0.0,1.0,nx)
y=0.3*np.sin(x*8)+0.4
ax2.plot(x,y,label='',path_effects=[path_effects.withTickedStroke()])
ax2.plot(x,y,label='C1',path_effects=[path_effects.withTickedStroke()])

ax2.legend()

Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp