| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -100,7 +100,7 @@ per-file-ignores = | |||
| 100 | 100 | tutorials/introductory/images.py: E402, E501 | |
| 101 | 101 | tutorials/introductory/pyplot.py: E402, E501 | |
| 102 | 102 | tutorials/introductory/sample_plots.py: E501 | |
| 103 | - tutorials/introductory/usage.py: E501 | ||
| 103 | + tutorials/introductory/usage.py: E703 | ||
| 104 | 104 | tutorials/text/annotations.py: E402, E501 | |
| 105 | 105 | tutorials/text/text_intro.py: E402 | |
| 106 | 106 | tutorials/text/text_props.py: E501 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,7 +25,7 @@ | |||
| 25 | 25 | # `.Axes.plot` to draw some data on the axes: | |
| 26 | 26 | ||
| 27 | 27 | fig, ax = plt.subplots() # Create a figure containing a single axes. | |
| 28 | - ax.plot([1, 2, 3, 4], [1, 4, 2, 3]) # Plot some data on the axes. | ||
| 28 | + ax.plot([1, 2, 3, 4], [1, 4, 2, 3]); # Plot some data on the axes. | ||
| 29 | 29 | ||
| 30 | 30 | ############################################################################### | |
| 31 | 31 | # .. _figure_parts: | |
@@ -123,14 +123,14 @@ | |||
| 123 | 123 | fig, ax = plt.subplots(figsize=(5, 2.7), constrained_layout=True) | |
| 124 | 124 | ax.scatter('a', 'b', c='c', s='d', data=data) | |
| 125 | 125 | ax.set_xlabel('entry a') | |
| 126 | - ax.set_ylabel('entry b') | ||
| 126 | + ax.set_ylabel('entry b'); | ||
| 127 | 127 | ||
| 128 | 128 | ############################################################################## | |
| 129 | 129 | # .. _coding_styles: | |
| 130 | 130 | # | |
| 131 | 131 | # Coding styles | |
| 132 | 132 | # ============= | |
| 133 | - | ||
| 133 | + # | ||
| 134 | 134 | # The object-oriented and the pyplot interfaces | |
| 135 | 135 | # --------------------------------------------- | |
| 136 | 136 | # | |
@@ -153,7 +153,7 @@ | |||
| 153 | 153 | ax.set_xlabel('x label') # Add an x-label to the axes. | |
| 154 | 154 | ax.set_ylabel('y label') # Add a y-label to the axes. | |
| 155 | 155 | ax.set_title("Simple Plot") # Add a title to the axes. | |
| 156 | - ax.legend() # Add a legend. | ||
| 156 | + ax.legend(); # Add a legend. | ||
| 157 | 157 | ||
| 158 | 158 | ############################################################################### | |
| 159 | 159 | # or the pyplot-style: | |
@@ -167,19 +167,19 @@ | |||
| 167 | 167 | plt.xlabel('x label') | |
| 168 | 168 | plt.ylabel('y label') | |
| 169 | 169 | plt.title("Simple Plot") | |
| 170 | - plt.legend() | ||
| 170 | + plt.legend(); | ||
| 171 | 171 | ||
| 172 | 172 | ############################################################################### | |
| 173 | 173 | # (In addition, there is a third approach, for the case when embedding | |
| 174 | 174 | # Matplotlib in a GUI application, which completely drops pyplot, even for | |
| 175 | - # figure creation. See the corresponding section in the gallery for more info | ||
| 176 | - # (:ref:`user_interfaces`).) | ||
| 175 | + # figure creation. See the corresponding section in the gallery for more info: | ||
| 176 | + # :ref:`user_interfaces`.) | ||
| 177 | 177 | # | |
| 178 | 178 | # Matplotlib's documentation and examples use both the OO and the pyplot | |
| 179 | 179 | # styles. In general, we suggest using the OO style, particularly for | |
| 180 | 180 | # complicated plots, and functions and scripts that are intended to be reused | |
| 181 | - # as part of a larger project. However, the pyplot style can be very conveneient | ||
| 182 | - # for quick interactive work. | ||
| 181 | + # as part of a larger project. However, the pyplot style can be very | ||
| 182 | + # conveneient for quick interactive work. | ||
| 183 | 183 | # | |
| 184 | 184 | # .. note:: | |
| 185 | 185 | # | |
@@ -189,9 +189,9 @@ | |||
| 189 | 189 | # Making a helper functions | |
| 190 | 190 | # ------------------------- | |
| 191 | 191 | # | |
| 192 | - # If you need to make the same plots over and over again with different data sets, | ||
| 193 | - # or want to easily wrap Matplotlib methods, use the recommended signature function | ||
| 194 | - # below. | ||
| 192 | + # If you need to make the same plots over and over again with different data | ||
| 193 | + # sets, or want to easily wrap Matplotlib methods, use the recommended | ||
| 194 | + # signature function below. | ||
| 195 | 195 | ||
| 196 | 196 | ||
| 197 | 197 | def my_plotter(ax, data1, data2, param_dict): | |
@@ -208,11 +208,9 @@ def my_plotter(ax, data1, data2, param_dict): | |||
| 208 | 208 | xdata = np.arange(len(data1)) # make an ordinal for this | |
| 209 | 209 | fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(5, 2.7)) | |
| 210 | 210 | my_plotter(ax1, data1, data2, {'marker': 'x'}) | |
| 211 | - my_plotter(ax2, data3, data4, {'marker': 'o'}) | ||
| 211 | + my_plotter(ax2, data3, data4, {'marker': 'o'}); | ||
| 212 | 212 | ||
| 213 | 213 | ############################################################################### | |
| 214 | - # These examples provide convenience for more complex graphs. | ||
| 215 | - # | ||
| 216 | 214 | # Note that if you want to install these as a python package, or any other | |
| 217 | 215 | # customizations you could use use one of the many templates on the web; | |
| 218 | 216 | # Matplotlib has one at `mpl-cookiecutter | |
@@ -232,7 +230,7 @@ def my_plotter(ax, data1, data2, param_dict): | |||
| 232 | 230 | x = np.arange(len(data1)) | |
| 233 | 231 | ax.plot(x, np.cumsum(data1), color='blue', linewidth=3, linestyle='--') | |
| 234 | 232 | l, = ax.plot(x, np.cumsum(data2), color='orange', linewidth=2) | |
| 235 | - l.set_linestyle(':') | ||
| 233 | + l.set_linestyle(':'); | ||
| 236 | 234 | ||
| 237 | 235 | ############################################################################### | |
| 238 | 236 | # Colors | |
@@ -246,7 +244,7 @@ def my_plotter(ax, data1, data2, param_dict): | |||
| 246 | 244 | ||
| 247 | 245 | fig, ax = plt.subplots(figsize=(5, 2.7)) | |
| 248 | 246 | x = np.arange(len(data1)) | |
| 249 | - ax.scatter(data1, data2, s=50, facecolor='C0', edgecolor='k') | ||
| 247 | + ax.scatter(data1, data2, s=50, facecolor='C0', edgecolor='k'); | ||
| 250 | 248 | ||
| 251 | 249 | ############################################################################### | |
| 252 | 250 | # Linewidths, linestyles, and markersizes | |
@@ -260,8 +258,8 @@ def my_plotter(ax, data1, data2, param_dict): | |||
| 260 | 258 | # Marker size depends on the method being used. `~.Axes.plot` specifies | |
| 261 | 259 | # markersize in points, and is generally the "diameter" or width of the | |
| 262 | 260 | # marker. `~.Axes.scatter` specifies markersize as approximately | |
| 263 | - # proportional to the visual area of the marker. There are also an array of | ||
| 264 | - # markerstyles available as string codes (see :mod:`~.matplotlib.markers`) or | ||
| 261 | + # proportional to the visual area of the marker. There is an array of | ||
| 262 | + # markerstyles available as string codes (see :mod:`~.matplotlib.markers`), or | ||
| 265 | 263 | # users can define their own `~.MarkerStyle` (see | |
| 266 | 264 | # :doc:`/gallery/lines_bars_and_markers/marker_reference`): | |
| 267 | 265 | ||
@@ -270,19 +268,19 @@ def my_plotter(ax, data1, data2, param_dict): | |||
| 270 | 268 | ax.plot(data2, 'd', label='data2') | |
| 271 | 269 | ax.plot(data3, 'v', label='data3') | |
| 272 | 270 | ax.plot(data4, 's', label='data4') | |
| 273 | - ax.legend() | ||
| 271 | + ax.legend(); | ||
| 274 | 272 | ||
| 275 | - ################################################################################ | ||
| 273 | + ############################################################################### | ||
| 276 | 274 | # | |
| 277 | 275 | # Labelling plots | |
| 278 | 276 | # =============== | |
| 279 | 277 | # | |
| 280 | 278 | # Axes labels and text | |
| 281 | 279 | # -------------------- | |
| 282 | 280 | # | |
| 283 | - # `~.Axes.set_xlabel`, `~.Axes.set_ylabel` and `~.Axes.set_title` are used to | ||
| 284 | - # add text in the indicated locations (see :doc:`/tutorials/text/text_intro` for | ||
| 285 | - # more discussion). Text can also be directly added to plots using | ||
| 281 | + # `~.Axes.set_xlabel`, `~.Axes.set_ylabel`, and `~.Axes.set_title` are used to | ||
| 282 | + # add text in the indicated locations (see :doc:`/tutorials/text/text_intro` | ||
| 283 | + # for more discussion). Text can also be directly added to plots using | ||
| 286 | 284 | # `~.Axes.text`: | |
| 287 | 285 | ||
| 288 | 286 | mu, sigma = 115, 15 | |
@@ -296,8 +294,7 @@ def my_plotter(ax, data1, data2, param_dict): | |||
| 296 | 294 | ax.set_title('Aardvark lengths\n (not really)') | |
| 297 | 295 | ax.text(75, .025, r'$\mu=115,\ \sigma=15$') | |
| 298 | 296 | ax.axis([55, 175, 0, 0.03]) | |
| 299 | - ax.grid(True) | ||
| 300 | - plt.show() | ||
| 297 | + ax.grid(True); | ||
| 301 | 298 | ||
| 302 | 299 | ############################################################################### | |
| 303 | 300 | # All of the `~.Axes.text` functions return a `matplotlib.text.Text` | |
@@ -341,7 +338,7 @@ def my_plotter(ax, data1, data2, param_dict): | |||
| 341 | 338 | ax.annotate('local max', xy=(2, 1), xytext=(3, 1.5), | |
| 342 | 339 | arrowprops=dict(facecolor='black', shrink=0.05)) | |
| 343 | 340 | ||
| 344 | - ax.set_ylim(-2, 2) | ||
| 341 | + ax.set_ylim(-2, 2); | ||
| 345 | 342 | ||
| 346 | 343 | ############################################################################### | |
| 347 | 344 | # In this basic example, both *xy* and *xytext* are in data coordinates. | |
@@ -359,7 +356,7 @@ def my_plotter(ax, data1, data2, param_dict): | |||
| 359 | 356 | ax.plot(np.arange(len(data1)), data1, label='data1') | |
| 360 | 357 | ax.plot(np.arange(len(data2)), data2, label='data2') | |
| 361 | 358 | ax.plot(np.arange(len(data3)), data3, 'd', label='data3') | |
| 362 | - ax.legend() | ||
| 359 | + ax.legend(); | ||
| 363 | 360 | ||
| 364 | 361 | ############################################################################## | |
| 365 | 362 | # Legends in Matplotlib are quite flexible in layout, placement, and what | |
@@ -369,9 +366,9 @@ def my_plotter(ax, data1, data2, param_dict): | |||
| 369 | 366 | # Axis scales and ticks | |
| 370 | 367 | # ===================== | |
| 371 | 368 | # | |
| 372 | - # Each Axes has two (or three) `~.axis.Axis` objects represnting the x- and y-axis. | ||
| 373 | - # These control the *scale* of the axis, the tick *Locators* and the tick | ||
| 374 | - # *Formatters*. | ||
| 369 | + # Each Axes has two (or three) `~.axis.Axis` objects represnting the x- and | ||
| 370 | + # y-axis. These control the *scale* of the axis, the tick *Locators* and the | ||
| 371 | + # tick *Formatters*. | ||
| 375 | 372 | # | |
| 376 | 373 | # Scales | |
| 377 | 374 | # ------ | |
@@ -388,7 +385,7 @@ def my_plotter(ax, data1, data2, param_dict): | |||
| 388 | 385 | axs[0].plot(xdata, data) | |
| 389 | 386 | ||
| 390 | 387 | axs[1].set_yscale('log') | |
| 391 | - axs[1].plot(xdata, data) | ||
| 388 | + axs[1].plot(xdata, data); | ||
| 392 | 389 | ||
| 393 | 390 | ############################################################################## | |
| 394 | 391 | # The scale sets the mapping from data values to spacing along the Axis. This | |
@@ -409,7 +406,7 @@ def my_plotter(ax, data1, data2, param_dict): | |||
| 409 | 406 | axs[1].plot(xdata, data1) | |
| 410 | 407 | axs[1].set_xticks(np.arange(0, 100, 30), ['zero', '30', 'sixty', '90']) | |
| 411 | 408 | axs[1].set_yticks([-1.5, 0, 1.5]) # note that we don't need to specify labels | |
| 412 | - axs[1].set_title('Manual ticks') | ||
| 409 | + axs[1].set_title('Manual ticks'); | ||
| 413 | 410 | ||
| 414 | 411 | ############################################################################## | |
| 415 | 412 | # Different scales can have different locators and formatters; for instance | |
@@ -421,15 +418,15 @@ def my_plotter(ax, data1, data2, param_dict): | |||
| 421 | 418 | # Plotting dates and strings | |
| 422 | 419 | # -------------------------- | |
| 423 | 420 | # | |
| 424 | - # Matplotlib can handle plotting arrays of dates and arrays of strings as | ||
| 421 | + # Matplotlib can handle plotting arrays of dates and arrays of strings, as | ||
| 425 | 422 | # well as floating point numbers. These get special locators and formatters | |
| 426 | 423 | # as appropriate. For dates: | |
| 427 | 424 | ||
| 428 | 425 | fig, ax = plt.subplots(figsize=(5, 3.7), constrained_layout=True) | |
| 429 | 426 | dates = np.arange(np.datetime64('2021-11-15'), np.datetime64('2021-12-25'), | |
| 430 | 427 | np.timedelta64(1, 'h')) | |
| 431 | 428 | data = np.cumsum(np.random.randn(len(dates))) | |
| 432 | - ax.plot(dates, data) | ||
| 429 | + ax.plot(dates, data); | ||
| 433 | 430 | ||
| 434 | 431 | ############################################################################## | |
| 435 | 432 | # For more information see the date examples | |
@@ -441,13 +438,13 @@ def my_plotter(ax, data1, data2, param_dict): | |||
| 441 | 438 | fig, ax = plt.subplots(figsize=(5, 2.7), constrained_layout=True) | |
| 442 | 439 | categories = ['turnips', 'rutabega', 'cucumber', 'pumpkins'] | |
| 443 | 440 | ||
| 444 | - ax.bar(categories, np.random.rand(len(categories))) | ||
| 441 | + ax.bar(categories, np.random.rand(len(categories))); | ||
| 445 | 442 | ||
| 446 | 443 | ############################################################################## | |
| 447 | 444 | # One caveat about categorical plotting is that some methods of parsing | |
| 448 | 445 | # text files return a list of strings, even if the strings all represent | |
| 449 | - # numbers or dates. If you pass 1000 strings Matplotlib will think you | ||
| 450 | - # meant 1000 categories and will add 1000 ticks to your plot. | ||
| 446 | + # numbers or dates. If you pass 1000 strings, Matplotlib will think you | ||
| 447 | + # meant 1000 categories and will add 1000 ticks to your plot! | ||
| 451 | 448 | # | |
| 452 | 449 | # Color mapped data | |
| 453 | 450 | # ================= | |
@@ -474,7 +471,7 @@ def my_plotter(ax, data1, data2, param_dict): | |||
| 474 | 471 | ||
| 475 | 472 | pc = axs[1, 1].scatter(data1, data2, c=data3, cmap='RdBu_r') | |
| 476 | 473 | fig.colorbar(pc, ax=axs[1, 1], extend='both') | |
| 477 | - axs[1, 1].set_title('scatter()') | ||
| 474 | + axs[1, 1].set_title('scatter()'); | ||
| 478 | 475 | ||
| 479 | 476 | ############################################################################## | |
| 480 | 477 | # Colormaps | |
@@ -507,7 +504,9 @@ def my_plotter(ax, data1, data2, param_dict): | |||
| 507 | 504 | # :doc:`/gallery/subplots_axes_and_figures/colorbar_placement` for | |
| 508 | 505 | # details. You can also change the appearance of colorbars with the | |
| 509 | 506 | # *extend* keyword to add arrows to the ends, and *shrink* and *aspect* to | |
| 510 | - # control the size. | ||
| 507 | + # control the size. Finally, the colorbar will have default Locators | ||
| 508 | + # and Formatters appropriate to the Norm. These can be changed as for | ||
| 509 | + # other axis objects. | ||
| 511 | 510 | # | |
| 512 | 511 | # | |
| 513 | 512 | # Working with multiple figures and axes | |
| Back | FazBrowse Home | New Git URL |
0 commit comments