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

savefig has sideeffects #6899

Closed
Closed
Milestone
@Kojoley

Description

@Kojoley

In my investigation of image comparison fails with pytest and xdist plugin I have discovered strange behavior. By changing the extensions order of the image comparison tests you will receive different output (and of course test failures).

I made extensions shufflelike this and gotthese results. From the log you can see that mostly affected are legend tests on svg backend. So any baseline image from the tests withlegend call is spoiled by pdf backend, except thelegend +tightbox.

I tried to compare figure state before and aftersavefig call but run into issue#6870.

Here is the way to reproduce the problem. You can compare output of the snippet with baseline images ofmatplotlib.tests.test_legend.test_legend_auto1 test, if you want.

# python savefig_sideeffects.py svg svg pdf svg# diff -u 0.svg 1.svg# diff -u 1.svg 3.svg# SOURCE_DATE_EPOCH=0 python savefig_sideeffects.py pdf pdf svg pdfimportnumpyasnpimportmatplotlibmatplotlib.use('agg')importmatplotlib.pylabasplt# matplotlib.testing.decorators.ImageComparisonTest.remove_textdefremove_text(figure):frommatplotlibimporttickerfigure.suptitle("")foraxinfigure.get_axes():ax.set_title("")ax.xaxis.set_major_formatter(ticker.NullFormatter())ax.xaxis.set_minor_formatter(ticker.NullFormatter())ax.yaxis.set_major_formatter(ticker.NullFormatter())ax.yaxis.set_minor_formatter(ticker.NullFormatter())try:ax.zaxis.set_major_formatter(ticker.NullFormatter())ax.zaxis.set_minor_formatter(ticker.NullFormatter())exceptAttributeError:pass# matplotlib.tests.test_legend.test_legend_auto1deftest_legend_auto1():'Test automatic legend placement'fig=plt.figure()ax=fig.add_subplot(111)x=np.arange(100)ax.plot(x,50-x,'o',label='y=1')ax.plot(x,x-50,'o',label='y=-1')ax.legend(loc=0)returnfigdefprepare():importmatplotlib.testingmatplotlib._init_tests()# matplotlib.testing.decorators.ImageComparisonTest.setup_classmatplotlib.testing.setup()matplotlib.style.use('classic')matplotlib.testing.set_font_settings_for_testing()fig=test_legend_auto1()remove_text(fig)returnfigdeftest(exts):fig=prepare()# this will stick svg path ids with the same valuesmatplotlib.rc('svg',hashsalt='asdf')forpinenumerate(exts):fig.savefig('%d.%s'%p)if__name__=='__main__':importsystest(sys.argv[1:])

This is the demonstration of the issue, wheresavefig with pdf backend has sideeffect on the nextsavefig with svg backend:

>python savefig_sideeffects.py svg svg pdf svg>diff -u 0.svg 1.svg>diff -u 1.svg 3.svg--- 1.svg       2016-08-04 00:29:52.429050200 +0300+++ 3.svg       2016-08-04 00:29:52.537061000 +0300@@ -462,18 +462,18 @@    </g>    <g>     <g>-     <path d="M 424.413 239.2965-L 511.2 239.2965-L 511.2 192.7035-L 424.413 192.7035+     <path d="M 424.469375 239.25225+L 511.2 239.25225+L 511.2 192.74775+L 424.469375 192.74775 z "/>     </g>     <g/>     <g>      <g>-      <use x="434.493" xlink:href="#mb9df33688a" y="204.36525"/>-      <use x="454.653" xlink:href="#mb9df33688a" y="204.36525"/>+      <use x="434.549375" xlink:href="#mb9df33688a" y="204.4095"/>+      <use x="454.709375" xlink:href="#mb9df33688a" y="204.4095"/>      </g>     </g>     <g>@@ -520,7 +520,7 @@ z "/>      </defs>-     <g transform="translate(470.493 209.40525)scale(0.144 -0.144)">+     <g transform="translate(470.549375 209.4495)scale(0.144 -0.144)">       <use xlink:href="#DejaVuSans-79"/>       <use x="59.179688" xlink:href="#DejaVuSans-3d"/>       <use x="142.96875" xlink:href="#DejaVuSans-31"/>@@ -529,8 +529,8 @@     <g/>     <g>      <g>-      <use x="434.493" xlink:href="#m3d71661f95" y="225.50175"/>-      <use x="454.653" xlink:href="#m3d71661f95" y="225.50175"/>+      <use x="434.549375" xlink:href="#m3d71661f95" y="225.546"/>+      <use x="454.709375" xlink:href="#m3d71661f95" y="225.546"/>      </g>     </g>     <g>@@ -543,7 +543,7 @@ z "/>      </defs>-     <g transform="translate(470.493 230.54175)scale(0.144 -0.144)">+     <g transform="translate(470.549375 230.586)scale(0.144 -0.144)">       <use xlink:href="#DejaVuSans-79"/>       <use x="59.179688" xlink:href="#DejaVuSans-3d"/>       <use x="142.96875" xlink:href="#DejaVuSans-2d"/>

Same happens to pdf after svg.

By accident, while fixing issue#6870, it seems that I have fixed this too. Test above now passes but there are 505 SVG baseline images affected and need update. I will open PR for this soon.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp