matplotlib, just like numpy, is one of those libraries which has so much legacy behind the import statement that it’s worth breaking Python style rules and using the at keyword to change the name of the imported library. Traditionally, matplotlib.pyplot is imported as plt, with the statement:
Using subplots
Two Y-Axis Example
This will produce the following graph:
Example matplotlib graph using two separate Y-axis.
Matching The Legend Text Color To The Plot Line Color
It can be a handy visual aid to set the legend color to the same color as the corresponding line on the plot. This can be done with the following code:
This will produce a plot which looks like:
Creating Animated Plots
When using the pillow writer, the GIF will not loop. When using the imagemagick writer, the GIF will loop.
Using The Basemap
Using A Specific Axis
Rather than Basemap automatically using/creating an axis for you, you can instead take a more object-orientated approach (which I recommend) and provide Basemap with the Axis object to use for drawing the map:
Adjusting The Size Of The Map
You can adjust the size of a basemap by calling plt.figure(figsize(15,15)) before making any calls to the Basemap class:
Setting Aspect Ratio Equal For A 3D Plot
Unfortunately, there is no built-in support for forcing the aspect ratio to be equal for a 3D plot. However you can do it yourself by calculating a bounding box from your plot objects and setting the limits yourself. Below is a function you can copy/paste into your own code. Pass in the Axes object to set the aspect ratio to equal. Note that you have to add the objects to the axes BEFORE calling this function.