matplotlib: How to assign the dpi of your figure to meet some set maximum file size?
There can not be such a mechanism, because the file size can only be determined by actually rendering the finished drawing to a file, and that must happen after setting up the figure (where you set the DPI). 
How, for example, should anyone know, before rendering your curve, how well it's compressible as PNG? Or how big the PDF you might alternatively generate might be, without knowing how many lines you'll plot?
Also, matplotlib potentially has a lot of different output formats.
Hence, no, this is impossible.
Just wondering if there is a tried and tested method for setting the dpi output of your figure in matplotlib to be governed by some maximum file size, e.g., 15MB.