Repository navigation
Conversation
Each case saved an SVG, a PDF and a PNG and then announced only the SVG, so the log read as though two thirds of the work had not happened. The line was wrong in the same way 43 times over, which is the more useful thing the report exposed: the four lines that end every case were copied out by hand, and the three savefig calls could disagree with each other or with the message without anything noticing. They are one call to a local helper now, and the options are forwarded rather than repeated, so an absent optional stays absent and a plain case still says nothing about facecolor or dpi. The file is a hundred lines shorter and each case ends with the name it is saved under.
imshow was drawing one rectangle per sample. That was written when SVG was the only backend and the API had no way to say "raster", and it stayed after draw_image was added, so draw_image had no callers and two of its three implementations were empty. The cost is per sample: an 8x16 image is 128 elements, and a 200x200 image would be 40000. Every format can place a raster in one object, so the whole image is now one draw_image call. SVG embeds a PNG in a data URI, which is what matplotlib does, and PDF writes an image XObject with the samples as a FlateDecode stream, sharing the compressor the PNG backend already has. On the small images in the test suite that is 12049 bytes of SVG down to 6532 and 14433 of PDF down to 4828; the ratio grows with the image. The raster is sent at roughly the size it is drawn rather than at data resolution. This is not a detail: a renderer asked to enlarge a 16x8 image will usually interpolate it, and at these sizes interpolation turns data into a blur. Repeating each sample a whole number of times is exactly nearest neighbour, so it invents nothing, and it took the imshow case rendered through cairosvg from 5.3 to 1.6 against matplotlib. image-rendering is set as well, for renderers that honour it. A blit assumes the samples are evenly spaced on the canvas, which stops being true the moment an axis is log, so the per-cell path stays for that case. It was about to become code nothing reached, so there is now a log-axis imshow case in the suite; it lands at 1.4 against matplotlib, which also warps the image rather than stretching it. The three backends agree on where the image goes and which way up it is, which is worth stating because it is the easy thing to get wrong: PDF draws an image into the unit square with the first row at the top, under a page matrix that has already flipped y, and fplot's own rows run up the extent, with origin="upper" expressed as a descending axis rather than as reversed data. Checked by comparing each backend against a vertically flipped reference: every one of them is ~1.5 the right way up and ~23 upside down.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
imshowwas drawing one rectangle per sample, sodraw_imagehad no callers and two of its three implementations were empty. The image is now onedraw_imagecall: SVG embeds a PNG data URI, PDF writes an image XObject sharing the PNG backend's compressor. On the suite's small images that is 12049 bytes of SVG down to 6532 and 14433 of PDF down to 4828, and the ratio grows with the image.The raster is sent at roughly the size it is drawn, because a renderer asked to enlarge a 16x8 image usually interpolates it into a blur; repeating each sample a whole number of times is exactly nearest neighbour. That took the imshow case through cairosvg from 5.3 to 1.6 against matplotlib.
A blit assumes evenly spaced samples, which a log axis breaks, so the per-cell path stays for that case and there is now a log-axis imshow case covering it (1.4 against matplotlib).
Also:
test_plotssaved three formats and announced only the SVG. The four repeated lines per case are now one call to a local helper, a hundred lines shorter.44/44 PNG at 1.88, 44/44 PDF at 2.08, 132/132 outputs byte-identical across flang and LFortran.