|
281 | 281 | # The `~matplotlib.axes.Axes.bar` and `~matplotlib.axes.Axes.barh` methods |
282 | 282 | # are wrapped by `~proplot.axes.bar_extras`, |
283 | 283 | # `~proplot.axes.apply_cycle`, and `~proplot.axes.standardize_1d`. |
| 284 | +# This means that `~matplotlib.axes.Axes.bar` and `~matplotlib.axes.Axes.barh` employ |
| 285 | +# default *x* or *y* coordinates if you failed to provide them explicitly. |
284 | 286 | # You can now *group* or *stack* columns of data by passing 2D arrays to |
285 | 287 | # `~matplotlib.axes.Axes.bar` or `~matplotlib.axes.Axes.barh`, just like in |
286 | | -# `pandas`_, or use different colors for negative and positive bars by |
287 | | -# passing ``negpos=True``. Also, `~matplotlib.axes.Axes.bar` and |
288 | | -# `~matplotlib.axes.Axes.barh` now employ "default" *x* coordinates if you |
289 | | -# failed to provide them explicitly. |
| 288 | +# `pandas`_. You can also use different colors for "negative" and "positive" |
| 289 | +# bars by passing ``negpos=True`` (the default colors are :rc:`negcolor` |
| 290 | +# and :rc:`poscolor`). |
290 | 291 | # |
291 | | -# To make filled "area" plots, use the new `~proplot.axes.Axes.area` and |
292 | | -# `~proplot.axes.Axes.areax` methods. These are alises for |
293 | | -# `~matplotlib.axes.Axes.fill_between` and |
294 | | -# `~matplotlib.axes.Axes.fill_betweenx`, which are wrapped by |
295 | | -# `~proplot.axes.fill_between_extras` and |
296 | | -# `~proplot.axes.fill_betweenx_extras`. You can now *stack* or *overlay* |
297 | | -# columns of data by passing 2D arrays to `~proplot.axes.Axes.area` and |
298 | | -# `~proplot.axes.Axes.areax`, just like in `pandas`_. You can also now draw |
299 | | -# area plots that change color when the fill boundaries cross each other by |
300 | | -# passing ``negpos=True`` to `~matplotlib.axes.Axes.fill_between`. The most |
301 | | -# common use case for this is highlighting negative and positive areas with |
302 | | -# different colors, as shown below. |
| 292 | +# The `~matplotlib.axes.Axes.fill_between` and `~matplotlib.axes.Axes.fill_betweenx` |
| 293 | +# commands are wrapped by `~proplot.axes.fill_between_extras` and |
| 294 | +# `~proplot.axes.fill_betweenx_extras`. They also now have the optional shorthands |
| 295 | +# `~proplot.axes.Axes.area` and `~proplot.axes.Axes.areax`. |
| 296 | +# You can now *stack* or *overlay* columns of data by passing 2D arrays to |
| 297 | +# to these commands, just like in `pandas`_. You can also draw area plots that |
| 298 | +# change color when the fill boundaries cross each other by passing ``negpos=True`` |
| 299 | +# (the default colors are :rc:`negcolor` and :rc:`poscolor`). The most common |
| 300 | +# use case for this is highlighting *negative* and *positive* areas with different |
| 301 | +# colors, as shown below. |
303 | 302 |
|
304 | 303 | # %% |
305 | 304 | import proplot as plot |
|
400 | 399 | # -------------------------- |
401 | 400 | # |
402 | 401 | # The `~matplotlib.axes.Axes.boxplot` and `~matplotlib.axes.Axes.violinplot` |
403 | | -# methods are now wrapped with `~proplot.axes.boxplot_extras`, |
| 402 | +# commands are wrapped by `~proplot.axes.boxplot_extras`, |
404 | 403 | # `~proplot.axes.violinplot_extras`, `~proplot.axes.apply_cycle`, |
405 | | -# and `~proplot.axes.standardize_1d`. These wrappers add some useful |
406 | | -# options and apply aesthetically pleasing default settings. They also |
407 | | -# automatically apply axis labels based on the `~pandas.DataFrame` column |
408 | | -# labels or the input *x* coordinate labels. |
| 404 | +# and `~proplot.axes.standardize_1d`. They also now have the optional shorthands |
| 405 | +# `~proplot.axes.Axes.boxes` and `~proplot.axes.Axes.violins`. The wrappers |
| 406 | +# apply aesthetically pleasing default settings and permit configuration using |
| 407 | +# keyword arguments like ``color``, ``boxcolor``, and ``fillcolor``. They also |
| 408 | +# automatically apply axis labels based on the `~pandas.DataFrame` or |
| 409 | +# `~xarray.DataArray` column labels or the input *x* coordinate labels. |
409 | 410 |
|
410 | 411 | # %% |
411 | 412 | import proplot as plot |
|
443 | 444 | ax = axs[2] |
444 | 445 | data = state.rand(100, 7) |
445 | 446 | colors = plot.Colors('pastel2') # list of colors from the cycle |
446 | | -ax.boxes(data, fillcolor=colors) |
| 447 | +ax.boxplot(data, fillcolor=colors, orientation='horizontal') |
447 | 448 | ax.format(title='Multiple colors', titleloc='uc', ymargin=0.15) |
448 | 449 |
|
449 | 450 |
|
450 | 451 | # %% [raw] raw_mimetype="text/restructuredtext" |
451 | | -# .. _ug_parametric: |
| 452 | +# .. _ug_lines: |
452 | 453 | # |
453 | | -# Parametric plots |
454 | | -# ---------------- |
| 454 | +# Line plots |
| 455 | +# ---------- |
455 | 456 | # |
456 | | -# To make "parametric" plots, use the new `~proplot.axes.Axes.parametric` |
457 | | -# method. Parametric plots are |
458 | | -# `~matplotlib.collections.LineCollection`\ s that map individual line |
459 | | -# segments to individual colors, where each segment represents a "parametric" |
460 | | -# coordinate (e.g., time). The parametric coordinates are specified with the |
461 | | -# `values` keyword argument. See `~proplot.axes.Axes.parametric` for details. |
462 | | -# As shown below, it is also easy to build colorbars from the |
463 | | -# `~matplotlib.collections.LineCollection` returned by |
464 | | -# `~proplot.axes.Axes.parametric`. |
| 457 | +# The `~matplotlib.axes.Axes.plot` command is wrapped by |
| 458 | +# `~proplot.axes.apply_cycle` and `~proplot.axes.standardize_1d`. |
| 459 | +# But in general, its behavior is the same -- ProPlot simply tries to expand |
| 460 | +# the flexibility of this command to the rest of the 1D plotting commands. |
| 461 | +# The new `~proplot.axes.Axes.plotx` command can be used just like |
| 462 | +# `~matplotlib.axes.Axes.plotx`, except a single argument is interpreted |
| 463 | +# as *x* coordinates (with default *y* coordinates inferred from the data), |
| 464 | +# and multiple arguments are interpreted as *y* and *x* coordinates (in that order). |
| 465 | +# This is analogous to `~matplotlib.axes.Axes.barh` and |
| 466 | +# `~matplotlib.axes.Axes.fill_betweenx`. |
| 467 | +# |
| 468 | +# As with the other 1D plotting commands, `~matplotlib.axes.Axes.step`, |
| 469 | +# `~matplotlib.axes.Axes.hlines`, `~matplotlib.axes.Axes.vlines`, and |
| 470 | +# `~matplotlib.axes.Axes.stem` are wrapped by `~proplot.axes.standardize_1d`. |
| 471 | +# `~proplot.axes.Axes.step` now use the property cycle, just like |
| 472 | +# `~matplotlib.axes.Axes.plot`. `~matplotlib.axes.Axes.vlines` and |
| 473 | +# `~matplotlib.axes.Axes.hlines` are also wrapped by `~proplot.axes.vlines_extras` |
| 474 | +# and `~proplot.axes.hlines_extras`, which can use |
| 475 | +# different colors for "negative" and "positive" lines using ``negpos=True`` |
| 476 | +# (the default colors are :rc:`negcolor` and :rc:`poscolor`). |
465 | 477 |
|
466 | 478 | # %% |
467 | 479 | import proplot as plot |
468 | 480 | import numpy as np |
469 | | -fig, axs = plot.subplots( |
470 | | - share=0, ncols=2, wratios=(2, 1), |
471 | | - figwidth='16cm', refaspect=(2, 1) |
472 | | -) |
473 | | -axs.format(suptitle='Parametric plots demo') |
474 | | -cmap = 'IceFire' |
475 | | - |
476 | | -# Sample data |
477 | 481 | state = np.random.RandomState(51423) |
478 | | -N = 50 |
479 | | -x = (state.rand(N) - 0.52).cumsum() |
480 | | -y = state.rand(N) |
481 | | -c = np.linspace(-N / 2, N / 2, N) # color values |
| 482 | +fig, axs = plot.subplots(ncols=2, nrows=2, share=0) |
| 483 | +axs.format(suptitle='Line plots demo', xlabel='xlabel', ylabel='ylabel') |
482 | 484 |
|
483 | | -# Parametric line with smooth gradations |
| 485 | +# Step |
484 | 486 | ax = axs[0] |
485 | | -m = ax.parametric( |
486 | | - x, y, c, cmap=cmap, lw=7, interp=5, capstyle='round', joinstyle='round' |
487 | | -) |
488 | | -ax.format(xlabel='xlabel', ylabel='ylabel', title='Line with smooth gradations') |
489 | | -ax.colorbar(m, loc='b', label='parametric coordinate', locator=5) |
490 | | - |
491 | | -# Sample data |
492 | | -N = 12 |
493 | | -radii = np.linspace(1, 0.2, N + 1) |
494 | | -angles = np.linspace(0, 4 * np.pi, N + 1) |
495 | | -x = radii * np.cos(1.4 * angles) |
496 | | -y = radii * np.sin(1.4 * angles) |
497 | | -c = np.linspace(-N / 2, N / 2, N + 1) |
| 487 | +data = state.rand(20, 4).cumsum(axis=1).cumsum(axis=0) |
| 488 | +cycle = ('blue7', 'gray5', 'red7', 'gray5') |
| 489 | +ax.step(data, cycle=cycle, labels=list('ABCD'), legend='ul', legend_kw={'ncol': 2}) |
| 490 | +ax.format(title='Step plot') |
498 | 491 |
|
499 | | -# Parametric line with stepped gradations |
| 492 | +# Stems |
500 | 493 | ax = axs[1] |
501 | | -m = ax.parametric(x, y, c, cmap=cmap, lw=15) |
502 | | -ax.format( |
503 | | - xlim=(-1, 1), ylim=(-1, 1), title='Step gradations', |
504 | | - xlabel='cosine angle', ylabel='sine angle' |
505 | | -) |
506 | | -ax.colorbar(m, loc='b', maxn=10, label='parametric coordinate') |
| 494 | +data = state.rand(20) |
| 495 | +ax.stem(data, linefmt='k-') |
| 496 | +ax.format(title='Stem plot') |
507 | 497 |
|
| 498 | +# Vertical lines |
| 499 | +gray = 'gray7' |
| 500 | +data = state.rand(20) - 0.5 |
| 501 | +ax = axs[2] |
| 502 | +ax.area(data, color=gray, alpha=0.2) |
| 503 | +ax.vlines(data, negpos=True, linewidth=2) |
| 504 | +ax.format(title='Vertical lines') |
| 505 | + |
| 506 | +# Horizontal lines |
| 507 | +ax = axs[3] |
| 508 | +ax.areax(data, color=gray, alpha=0.2) |
| 509 | +ax.hlines(data, negpos=True, linewidth=2) |
| 510 | +ax.format(title='Horizontal lines') |
508 | 511 |
|
509 | 512 | # %% [raw] raw_mimetype="text/restructuredtext" |
510 | 513 | # .. _ug_scatter: |
511 | 514 | # |
512 | | -# Other plotting methods |
513 | | -# ---------------------- |
| 515 | +# Scatter plots |
| 516 | +# ------------- |
514 | 517 | # |
515 | | -# The `~matplotlib.axes.Axes.scatter` method is now wrapped by |
| 518 | +# The `~matplotlib.axes.Axes.scatter` command is wrapped by |
516 | 519 | # `~proplot.axes.scatter_extras`, `~proplot.axes.apply_cycle`, and |
517 | 520 | # `~proplot.axes.standardize_1d`. This means that |
518 | | -# `~matplotlib.axes.Axes.scatter` now accepts 2D arrays, just like |
519 | | -# `~matplotlib.axes.Axes.plot`. Also, successive calls to |
520 | | -# `~matplotlib.axes.Axes.scatter` now use the property cycler properties |
521 | | -# (e.g., `color`, `marker`, and `markersize`), and |
522 | | -# `~matplotlib.axes.Axes.scatter` now optionally accepts keywords that look |
523 | | -# like `~matplotlib.axes.Axes.plot` keywords (e.g., `color` instead of `c` and |
524 | | -# `markersize` instead of `s`). |
| 521 | +# `~matplotlib.axes.Axes.scatter` now accepts 2D *y* coordinates and permits |
| 522 | +# omitting *x* coordinates, just like `~matplotlib.axes.Axes.plot`. |
| 523 | +# `~matplotlib.axes.Axes.scatter` now also accepts keywords that look like |
| 524 | +# `~matplotlib.axes.Axes.plot` keywords (e.g., `color` instead of `c` and |
| 525 | +# `markersize` instead of `s`). This way, `~matplotlib.axes.Axes.scatter` can |
| 526 | +# optionally be used simply to "plot markers, not lines" without changing the |
| 527 | +# input arguments relative to `~matplotlib.axes.Axes.plot`. |
525 | 528 | # |
526 | | -# ProPlot also supports property cycling for `~proplot.axes.Axes.step` plots |
527 | | -# and wraps the `~matplotlib.axes.Axes.vlines` and `~matplotlib.axes.Axes.hlines` |
528 | | -# methods with `~proplot.axes.vlines_extras` and `~proplot.axes.hlines_extras`, |
529 | | -# which adds the ability to use different colors for "negative" and "positive" lines. |
| 529 | +# Just like `~matplotlib.axes.Axes.plot`, the property cycle is used |
| 530 | +# with `~matplotlib.axes.Axes.scatter` plots by default. It can be changed |
| 531 | +# using the `cycle` keyword argument, and it can include properties like `marker` |
| 532 | +# and `markersize`. The colormap `cmap` and normalizer `norm` used with the |
| 533 | +# optional `c` color array are now passed through the `~proplot.constructor.Colormap` |
| 534 | +# and `~proplot.constructor.Norm` constructor functions, and the the `s` marker |
| 535 | +# size array can now be conveniently scaled using the arguments `smin` and `smax` |
| 536 | +# (analogous to `vmin` and `vmax` used for colors). |
530 | 537 |
|
531 | 538 | # %% |
532 | 539 | import proplot as plot |
|
562 | 569 | ) |
563 | 570 | axs.format(xlabel='xlabel', ylabel='ylabel') |
564 | 571 |
|
| 572 | +# %% [raw] raw_mimetype="text/restructuredtext" |
| 573 | +# .. _ug_parametric: |
| 574 | +# |
| 575 | +# Parametric plots |
| 576 | +# ---------------- |
| 577 | +# |
| 578 | +# To make "parametric" plots, use the new `~proplot.axes.Axes.parametric` |
| 579 | +# command. Parametric plots are `~matplotlib.collections.LineCollection`\ s that |
| 580 | +# map individual line segments to individual colors, where each segment represents a |
| 581 | +# "parametric" coordinate (e.g., time). The parametric coordinates are specified with |
| 582 | +# the `values` keyword argument. See `~proplot.axes.Axes.parametric` for details. As |
| 583 | +# shown below, it is also easy to build colorbars from the |
| 584 | +# `~matplotlib.collections.LineCollection` returned by `~proplot.axes.Axes.parametric`. |
| 585 | + |
565 | 586 | # %% |
566 | 587 | import proplot as plot |
567 | 588 | import numpy as np |
| 589 | +fig, axs = plot.subplots( |
| 590 | + share=0, ncols=2, wratios=(2, 1), |
| 591 | + figwidth='16cm', refaspect=(2, 1) |
| 592 | +) |
| 593 | +axs.format(suptitle='Parametric plots demo') |
| 594 | +cmap = 'IceFire' |
| 595 | + |
| 596 | +# Sample data |
568 | 597 | state = np.random.RandomState(51423) |
569 | | -fig, axs = plot.subplots(ncols=2, nrows=2, share=0) |
570 | | -axs.format(suptitle='Line plots demo', xlabel='xlabel', ylabel='ylabel') |
| 598 | +N = 50 |
| 599 | +x = (state.rand(N) - 0.52).cumsum() |
| 600 | +y = state.rand(N) |
| 601 | +c = np.linspace(-N / 2, N / 2, N) # color values |
571 | 602 |
|
572 | | -# Step |
| 603 | +# Parametric line with smooth gradations |
573 | 604 | ax = axs[0] |
574 | | -data = state.rand(20, 4).cumsum(axis=1).cumsum(axis=0) |
575 | | -cycle = ('blue7', 'gray5', 'red7', 'gray5') |
576 | | -ax.step(data, cycle=cycle, labels=list('ABCD'), legend='ul', legend_kw={'ncol': 2}) |
577 | | -ax.format(title='Step plot') |
578 | | - |
579 | | -# Stems |
580 | | -ax = axs[1] |
581 | | -data = state.rand(20) |
582 | | -ax.stem(data, linefmt='k-') |
583 | | -ax.format(title='Stem plot') |
| 605 | +m = ax.parametric( |
| 606 | + x, y, c, cmap=cmap, lw=7, interp=5, capstyle='round', joinstyle='round' |
| 607 | +) |
| 608 | +ax.format(xlabel='xlabel', ylabel='ylabel', title='Line with smooth gradations') |
| 609 | +ax.colorbar(m, loc='b', label='parametric coordinate', locator=5) |
584 | 610 |
|
585 | | -# Vertical lines |
586 | | -gray = 'gray7' |
587 | | -data = state.rand(20) - 0.5 |
588 | | -ax = axs[2] |
589 | | -ax.area(data, color=gray, alpha=0.2) |
590 | | -ax.vlines(data, negpos=True, linewidth=2) |
591 | | -ax.format(title='Vertical lines') |
| 611 | +# Sample data |
| 612 | +N = 12 |
| 613 | +radii = np.linspace(1, 0.2, N + 1) |
| 614 | +angles = np.linspace(0, 4 * np.pi, N + 1) |
| 615 | +x = radii * np.cos(1.4 * angles) |
| 616 | +y = radii * np.sin(1.4 * angles) |
| 617 | +c = np.linspace(-N / 2, N / 2, N + 1) |
592 | 618 |
|
593 | | -# Horizontal lines |
594 | | -ax = axs[3] |
595 | | -ax.areax(data, color=gray, alpha=0.2) |
596 | | -ax.hlines(data, negpos=True, linewidth=2) |
597 | | -ax.format(title='Horizontal lines') |
| 619 | +# Parametric line with stepped gradations |
| 620 | +ax = axs[1] |
| 621 | +m = ax.parametric(x, y, c, cmap=cmap, lw=15) |
| 622 | +ax.format( |
| 623 | + xlim=(-1, 1), ylim=(-1, 1), title='Step gradations', |
| 624 | + xlabel='cosine angle', ylabel='sine angle' |
| 625 | +) |
| 626 | +ax.colorbar(m, loc='b', maxn=10, label='parametric coordinate') |
0 commit comments