set ( ylabel = 'Popularity', ylim = map ( lambda x : 1.08 * x, )) for ax in ax1, ax2 : _formatAxes ( ax ) plt. set ( ylabel = 'Friendliness', ylim = map ( lambda x : 1.08 * x, ) ) ax2. You already created your figure and assigned to variable fig. It defaults to (6,4) in your plot since you did not set it. Set the figsize in your call to plt.subplots. bar ( x, popularity, align = 'center', color = 'gray' ) ax1. 1 Answer Sorted by: 21 Your call to plt.figure (figsize (12,5)) is creating a new empty figure different from your already declared fig from the first step. bar ( x, friendliness, align = 'center', color = 'gray' ) ax2. axhline ( y = 0, color = 'black' ) x = np. Code: from matplotlib import pyplot as plt import numpy as np x np.linspace (0, 10, 100) y 4 + 2np.sin (2x) fig, axs plt.subplots () plt.xlabel ('time') plt.ylabel ('amplitude') plt.title ('y sin (x)') axs.plot (x, y, linewidth 3.0) axs.set (xlim (0, 8), xticksnp.arange (1, 8), ylim (0, 8), yticksnp.arange (1, 8)) plt. 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!) You can use plt.figure (figsize (16,8)) to change figure size of a single plot and with up to two subplots. (In matplotlib terms, this sets the aspect ratio of the plot to 1. Combined with the figsize argument, this allows us to control. equal: Set axes scales such that one cm/inch in the y-direction is the same as one cm/inch in the x-direction. 1 figsizea b plt.subplots fig, ax plt.subplots(figsize (a, b)) 1 fig (Figure)ax (axis)ax fig, ax plt.subplots() fig plt.figure() ax fig. although we still need a good way to hide the axis labels in the subplot on the right hand side.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |