|
10 | 10 | frommatplotlibimportdviread |
11 | 11 | frommatplotlib.figureimportFigure |
12 | 12 | importmatplotlib.pyplotasplt |
13 | | -frommatplotlib.testing.decoratorsimportimage_comparison |
| 13 | +frommatplotlib.testing.decoratorsimportimage_comparison,check_figures_equal |
14 | 14 |
|
15 | 15 |
|
16 | 16 | needs_usetex=pytest.mark.skipif( |
@@ -94,6 +94,94 @@ def test_bold_font_output_with_none_fonttype(): |
94 | 94 | ax.set_title('bold-title',fontweight='bold') |
95 | 95 |
|
96 | 96 |
|
| 97 | +@check_figures_equal(tol=20) |
| 98 | +deftest_rasterized(fig_test,fig_ref): |
| 99 | +t=np.arange(0,100)* (2.3) |
| 100 | +x=np.cos(t) |
| 101 | +y=np.sin(t) |
| 102 | + |
| 103 | +ax_ref=fig_ref.subplots() |
| 104 | +ax_ref.plot(x,y,"-",c="r",lw=10) |
| 105 | +ax_ref.plot(x+1,y,"-",c="b",lw=10) |
| 106 | + |
| 107 | +ax_test=fig_test.subplots() |
| 108 | +ax_test.plot(x,y,"-",c="r",lw=10,rasterized=True) |
| 109 | +ax_test.plot(x+1,y,"-",c="b",lw=10,rasterized=True) |
| 110 | + |
| 111 | + |
| 112 | +@check_figures_equal() |
| 113 | +deftest_rasterized_ordering(fig_test,fig_ref): |
| 114 | +t=np.arange(0,100)* (2.3) |
| 115 | +x=np.cos(t) |
| 116 | +y=np.sin(t) |
| 117 | + |
| 118 | +ax_ref=fig_ref.subplots() |
| 119 | +ax_ref.set_xlim(0,3) |
| 120 | +ax_ref.set_ylim(-1.1,1.1) |
| 121 | +ax_ref.plot(x,y,"-",c="r",lw=10,rasterized=True) |
| 122 | +ax_ref.plot(x+1,y,"-",c="b",lw=10,rasterized=False) |
| 123 | +ax_ref.plot(x+2,y,"-",c="g",lw=10,rasterized=True) |
| 124 | +ax_ref.plot(x+3,y,"-",c="m",lw=10,rasterized=True) |
| 125 | + |
| 126 | +ax_test=fig_test.subplots() |
| 127 | +ax_test.set_xlim(0,3) |
| 128 | +ax_test.set_ylim(-1.1,1.1) |
| 129 | +ax_test.plot(x,y,"-",c="r",lw=10,rasterized=True,zorder=1.1) |
| 130 | +ax_test.plot(x+2,y,"-",c="g",lw=10,rasterized=True,zorder=1.3) |
| 131 | +ax_test.plot(x+3,y,"-",c="m",lw=10,rasterized=True,zorder=1.4) |
| 132 | +ax_test.plot(x+1,y,"-",c="b",lw=10,rasterized=False,zorder=1.2) |
| 133 | + |
| 134 | + |
| 135 | +deftest_count_bitmaps(): |
| 136 | +defcount_tag(fig,tag): |
| 137 | +fd=BytesIO() |
| 138 | +fig.savefig(fd,format='svg') |
| 139 | +fd.seek(0) |
| 140 | +buf=fd.read().decode() |
| 141 | +fd.close() |
| 142 | +open("test.svg","w").write(buf) |
| 143 | +returnbuf.count("<%s"%tag) |
| 144 | + |
| 145 | +# No rasterized elements |
| 146 | +fig1=plt.figure() |
| 147 | +ax1=fig1.add_subplot(1,1,1) |
| 148 | +ax1.set_axis_off() |
| 149 | +forninrange(5): |
| 150 | +ax1.plot([0,20], [0,n],"b-",rasterized=False) |
| 151 | +assertcount_tag(fig1,"image")==0 |
| 152 | +assertcount_tag(fig1,"path")==6# axis patch plus lines |
| 153 | + |
| 154 | +# rasterized can be merged |
| 155 | +fig2=plt.figure() |
| 156 | +ax2=fig2.add_subplot(1,1,1) |
| 157 | +ax2.set_axis_off() |
| 158 | +forninrange(5): |
| 159 | +ax2.plot([0,20], [0,n],"b-",rasterized=True) |
| 160 | +assertcount_tag(fig2,"image")==1 |
| 161 | +assertcount_tag(fig2,"path")==1# axis patch |
| 162 | + |
| 163 | +# rasterized can't be merged without effecting draw order |
| 164 | +fig3=plt.figure() |
| 165 | +ax3=fig3.add_subplot(1,1,1) |
| 166 | +ax3.set_axis_off() |
| 167 | +forninrange(5): |
| 168 | +ax3.plot([0,20], [n,0],"b-",rasterized=False) |
| 169 | +ax3.plot([0,20], [0,n],"b-",rasterized=True) |
| 170 | +assertcount_tag(fig3,"image")==5 |
| 171 | +assertcount_tag(fig3,"path")==6 |
| 172 | + |
| 173 | +# rasterized whole axes |
| 174 | +fig4=plt.figure() |
| 175 | +ax4=fig4.add_subplot(1,1,1) |
| 176 | +ax4.set_axis_off() |
| 177 | +ax4.set_rasterized(True) |
| 178 | +forninrange(5): |
| 179 | +ax4.plot([0,20], [n,0],"b-",rasterized=False) |
| 180 | +ax4.plot([0,20], [0,n],"b-",rasterized=True) |
| 181 | +assertcount_tag(fig4,"image")==1 |
| 182 | +assertcount_tag(fig4,"path")==1 |
| 183 | + |
| 184 | + |
97 | 185 | @needs_usetex |
98 | 186 | deftest_missing_psfont(monkeypatch): |
99 | 187 | """An error is raised if a TeX font lacks a Type-1 equivalent""" |
|