set ( ylabel = 'Friendliness', ylim = map ( lambda x : 1.08 * x, ) ) ax2. ![]() bar ( x, popularity, align = 'center', color = 'gray' ) ax1. bar ( x, friendliness, align = 'center', color = 'gray' ) ax2. axhline ( y = 0, color = 'black' ) x = np. set ( xticks = x, xticklabels = animals ) ax. subplots_adjust ( hspace = 0 ) def _formatAxes ( ax ): ax. data = animals, friendliness, popularity = zip ( * data ) fig, ( ax1, ax2 ) = plt. # %load exercises/4.2-spines_ticks_and_subplot_spacing.py import matplotlib.pyplot as plt import numpy as np # Try to reproduce the figure shown in images/exercise_4.2.png # This one is a bit trickier! # Here's the data. That doesn't mean that the axes "box" will be square, though!) (In matplotlib terms, this sets the aspect ratio of the plot to 1. equal: Set axes scales such that one cm/inch in the y-direction is the same as one cm/inch in the x-direction.tight: Set axes limits to the exact range of the data.There are other options as well see the documentation for full details. ![]() ![]() However, you'll probably use axis mostly with either the "tight" or "equal" options. If you'd like to manually set all of the x/y limits at once, you can use ax.axis for this, as well (note that we're calling it with a single argument that's a sequence, not 4 individual arguments): ax.axis() If you ever need to get all of the current plot limits, calling ax.axis() with no arguments will return the xmin/max/etc: xmin, xmax, ymin, ymax = ax.axis() The ax.axis(.) method is a convienent way of controlling the axes limits and enabling/disabling autoscaling.
0 Comments
Leave a Reply. |