Handling transparency
When creating figures, they are rarely meant to be used as alone. For instance, figures can be part of a website or a presentation. In such cases, the figures will have to be integrated with other graphics. Transparency is important for such integration—figures will blend in an aesthetically pleasing and consistent manner with their background. In this recipe, we are going to see how to output figures with transparency.
How to do it...
To demonstrate transparency, we are going to create a figure and embed it in a webpage. The figure is going to blend with the webpage background. All the files that are created in this recipe should be in the same directory. We are going to do the following in this section:
Render a figure to a PNG file, with a transparent background
Make a HTML page that includes a figure
Rendering a figure to a PNG file with a transparent background
To render a figure to a PNG file, we will again use pyplot.savefig()
. However, the optional parameter transparent...