%global _empty_manifest_terminate_build 0 Name: python-mpl-plotter Version: 5.5.0 Release: 1 Summary: Publication-quality data representation library based on Matplotlib. License: GNU General Public License v3 (GPLv3) URL: https://github.com/alopezrivera/mpl_plotter Source0: https://mirrors.nju.edu.cn/pypi/web/packages/de/5b/690e2f94f224b27f7315197770311fe07895a9128d50035a429e760d6949/mpl_plotter-5.5.0.tar.gz BuildArch: noarch %description Two more examples (results in the table below): 1. We can add some customization to make our line look a bit better: line(show=True, pad_demo=True, spines_removed=None) Our line has now some margins to breathe while the ticks are placed at the maximum and minimums of our curve, and no spines are removed. 2. Lastly, an example using some of the parameters you can change: line(norm=True, line_width=4, title="Custom Line", title_font="Pump Triline", title_size=40, title_color="orange", label_x="x", label_y="$\Psi$", label_size_x=30, label_size_y=20, label_pad_x=-0.05, label_pad_y=10, label_rotation_y=0, aspect=1, pad_demo=True, workspace_color="darkred", grid=True, grid_color="grey", tick_color="darkgrey", tick_decimals=4, tick_number_x=12, tick_number_y=12, tick_rotation_x=35, color_bar=True, cb_tick_number=5, cb_pad=0.05, show=True) | [1](https://github.com/alopezrivera/mpl_plotter/blob/master/demo/scripts/line2.py#L13) | [2](https://github.com/alopezrivera/mpl_plotter/blob/master/demo/scripts/line2.py#L21) | | --- | --- | | ![alt text](demo/gallery/2d/medium_line.png "Some customization") | ![alt text](demo/gallery/2d/custom_line.png "Showcase") | ### 4.2 3D Same applies in 3D. | [0](https://github.com/alopezrivera/mpl_plotter/blob/master/demo/scripts/line3.py#L5) | [1](https://github.com/alopezrivera/mpl_plotter/blob/master/demo/scripts/line3.py#L15) | [2](https://github.com/alopezrivera/mpl_plotter/blob/master/demo/scripts/line3.py#L31) | |---|---|---| |![alt text](demo/gallery/3d/basic_line.png "Basic")|![alt text](demo/gallery/3d/medium_line.png "Some customization")|![alt text](demo/gallery/3d/custom_line.png "Showcase")| # 5. Curve comparisons and multiple pane plots `from mpl_plotter.two_d import comparison, panes` ### 5.1 `comparison` Plot any number of curves in a single plot. Axis limits will be set to the maximum and minimum of all your curves. No data will be left out, among other niceties. #### Data input Inputs must match (2 `x`s and 3 `y`s won't work), BUT the following inputs are all valid: | x | y | result | notes | | --- | --- | --- | --- | | array | array | 1 | | | array | [array, array] | 2 | Both `y`s share `x` | | [array, array] | [array, array] | 2 | Each `y` has an `x` | | [n*[array]] | [n*[array]] | n | Each `y` has an `x` | #### Plotting methods You can specify **different plotting methods for each curve in the plot**, a custom one for all curves, or not specify any (defaulting to lines). How? Check the code block below. This is nice as it allows you to crisply combine lines, scatter plots and any other of the MPL Plotter plotting methods. #### Other arguments As to any and all other arguments: - **Singular arguments**: the regular MPL Plotter plotting class arguments. Apply to all curves in the plot. - **Plural arguments**: pass a list of arguments, one for each curve. The result is as you'd imagine. ``` from mpl_plotter.two_d import comparison, line, scatter def f(x, y, **kwargs): line(x, y, line_width=2, **kwargs) def g(x, y, **kwargs): scatter(x, y, marker="D", point_size=10, **kwargs) def h(x, y, **kwargs): scatter(x, y, marker="s", point_size=5, **kwargs) comparison([x, x, x], [u, v, w], [f, g, h], plot_labels=["sin", "cos", "tan"], zorders=[1, 2, 3], colors=['C1', 'C2', 'C3'], alphas=[0.5, 0.5, 1], x_custom_tick_labels=[0, r"$\frac{\pi}{8}$", r"$\frac{\pi}{4}$"], show=show, backend=backend ) ``` ![alt text](demo/gallery/2d/comparison_custom.png "Curve comparison") ### 5.2 `panes` The panes function allows for the plotting of a series of graphs in side-by-side panes. As to data input, the table below applies. It uses the `comparison`, function under the hood so the same input guidelines apply for all other inputs. | x | y | result | notes | | --- | --- | --- | --- | | array | array | 11 | | | array | [array, array] | 12 | Both `y`s share `x` | | [n*[array]] | [n*[array]] | 1n | Each `y` has an `x` | | array | [array, array] | 21 | Both `y`s share `x` | | [array, array] | [array, array] | 21 | Each `y` has an `x` | | array | [n*[array], n*[array]] | 2n | All curves in all (2) panes share a single `x` | | [array, array] | [n*[array], n*[array]] | 2n | All curves in each pane share an `x` | | [n*[array], n*[array]] | [n*[array], n*[array]] | 2n | All curves in all (2) panes have their own `x` | | [n*[array], ... up to m] | [n*[array], ... up to m] | mn | All curves in all panes have their own `x` | ### Code The following plots one curve per pane (3 in total): ``` panes(x, # Horizontal vector [u, v, y], # List of curves to be plotted ["u", "v", "y"], # List of vertical axis labels ["a", "b", "c"] # List of legend labels ) ``` ![alt text](demo/gallery/2d/pane_single.png "Single-curve panes") And the following plots an arbitrary number of curves per pane. As you can see, you just need to input `n` **lists** of `m` curves (where `m`=2 in the example below), and you will get a plot with `n` panes, with `m` curves in each. ``` panes(x, # Horizontal vector [[u, uu], [v, vv], [y, yy]], # List of pairs of curves to be compared ["u", "v", "y"], # List of vertical axis labels ["a", "b"] # List of legend labels ) ``` ![alt text](demo/gallery/2d/pane_comparison.png "Multiple-curve comparison panes") ### Demo Preposterous demonstration to illustrate the **n** panes, **m** curves concept. The code for these is available in `tests/test_panes.py`. ![alt text](demo/gallery/2d/pane_alot.png "There's a lot") ![alt text](demo/gallery/2d/pane_alot_comparison.png "Lots of triplets") # 6. Presets TL;DR: Take a parameter `toml` and forget about function inputs. ### 6.1 Standard presets Standard presets are available to remove overhead. They're tailored for my use cases but you may find them useful anyway. | ![alt text](demo/gallery/2d/preset_publication_scatter.png "Publication preset")| ![alt text](demo/gallery/2d/preset_publication_heatmap.png "Publication preset") | ![alt text](demo/gallery/2d/preset_publication_quiver.png "Publication preset") | ![alt text](demo/gallery/2d/preset_publication_streamline.png "Publication preset") | ![alt text](demo/gallery/2d/preset_publication_fill.png "Publication preset") | ![alt text](demo/gallery/3d/preset_publication_line.png "Publication preset") | ![alt text](demo/gallery/3d/preset_publication_scatter.png "Publication preset") | ![alt text](demo/gallery/3d/preset_publication_surface.png "Publication preset") | | --- | --- | --- | --- | --- | --- | --- | --- | | ![alt text](demo/gallery/2d/preset_precision_scatter.png "Precision preset")| ![alt text](demo/gallery/2d/preset_precision_heatmap.png "Precision preset") | ![alt text](demo/gallery/2d/preset_precision_quiver.png "Precision preset") | ![alt text](demo/gallery/2d/preset_precision_streamline.png "Precision preset") | ![alt text](demo/gallery/2d/preset_precision_fill.png "Precision preset") | ![alt text](demo/gallery/3d/preset_precision_line.png "Precision preset") | ![alt text](demo/gallery/3d/preset_precision_scatter.png "Precision preset") | ![alt text](demo/gallery/3d/preset_precision_surface.png "Precision preset") | #### _Publication_ It is a common mistake to make a figure for a paper with unreadable labels. This preset tries to solve that, generating plots optimized to be printed on a small format, in side-by-side plots or embedded in a column of text. from mpl_plotter.presets.precision import two_d from mpl_plotter.color.schemes import one # Custom colorscheme x = np.linspace(0, 4, 1000) y = np.exp(x) z = abs(np.sin(x)*np.exp(x)) two_d.line(x, z, aspect=0.05, color=one()[-2], show=True) ![alt text](demo/gallery/2d/preset_publication_line.png "Publication preset") #### _Precision_ Made to plot functions large on the screen, with equal x and y scales to avoid skewing the variables, and many ticks to visually inspect a signal. from mpl_plotter.presets.precision import two_d two_d.line(x, z, aspect=0.05, color=one()[-2], show=True) ![alt text](demo/gallery/2d/preset_precision_line.png "Precision preset") ### 6.2 Custom presets Example workflow follows. For further reference check [the preset tests](https://github.com/alopezrivera/mpl_plotter/blob/master/tests/test_presets.py). 1. Import the preset creation function ``` from mpl_plotter.presets import preset ``` 2. Create a preset, either from a plotter, ``` from mpl_plotter.two_d import line _preset = preset(line) ``` or from a dimension. In this case, the preset will contain all common parameters to all plots in 2 or 3 dimensions. ``` _preset = preset(dim=2) ``` The preset is a dictionary. You can edit its parameters as you would expect. However, it is more convenient to 3. Save your preset in a `toml` file. This will yield you a `toml` file containing all parameters for your plot or dimension, allowing you to easily inspect defaults and tailor settings to your liking. You may edit this file as you please, as long as you do not infringe on its syntax. ``` _preset.save('tests/presets/test.toml') ``` 4. Load the file in the same -or a different session. ``` from mpl_plotter.presets import preset _preset = preset.load('tests/presets/test.toml') ``` 5. Import an MPL Plotter preset plotter and load it with your preset ``` from mpl_plotter.presets import two_d _two_d = two_d(preset=_preset) ``` 6. Plot as you wish ``` _two_d.line(show=True) _two_d.scatter(show=True) _two_d.<...> ``` # 7. Matplotlib ### 7.1 Retrieving axes, figures The axis and figure on which each class draws are instance attributes. To retrieve them and continue modifications using standard Matplotlib: from mpl_plotter.two_d import line my_plot = line() ax, fig = my_plot.ax, my_plot.fig With the axis and figure, most Matplotlib functions out there can be used to further modify your plots. ### 7.2 Using Matplotlib's axis tiling Matplotlib allows for subplot composition using `subplot2grid`. This can be used in combination with MPL Plotter: Importantly: - The auxiliary function `figure` (`from mpl_plotter figure`) sets up a figure in a chosen backend. This is convenient, as if the figure is created with `plt.figure()`, only the default non-interactive Matplotlib backend will be available, unless `matplotlib.use()` is specified before importing `pyplot`. ``` from mpl_plotter import figure from mpl_plotter.two_d import line, quiver, streamline, fill_area backend = "Qt5Agg" # None -> regular non-interactive matplotlib output figure(figsize=(10, 10), backend=backend) ax0 = plt.subplot2grid((2, 2), (0, 0), rowspan=1) ax1 = plt.subplot2grid((2, 2), (1, 0), rowspan=1) ax2 = plt.subplot2grid((2, 2), (0, 1), rowspan=1) ax3 = plt.subplot2grid((2, 2), (1, 1), rowspan=1) axes = [ax0, ax1, ax2, ax3] plots = [line, quiver, streamline, fill_area] for i in range(len(plots)): plots[i](ax=axes[i]) plt.show() ``` %package -n python3-mpl-plotter Summary: Publication-quality data representation library based on Matplotlib. Provides: python-mpl-plotter BuildRequires: python3-devel BuildRequires: python3-setuptools BuildRequires: python3-pip %description -n python3-mpl-plotter Two more examples (results in the table below): 1. We can add some customization to make our line look a bit better: line(show=True, pad_demo=True, spines_removed=None) Our line has now some margins to breathe while the ticks are placed at the maximum and minimums of our curve, and no spines are removed. 2. Lastly, an example using some of the parameters you can change: line(norm=True, line_width=4, title="Custom Line", title_font="Pump Triline", title_size=40, title_color="orange", label_x="x", label_y="$\Psi$", label_size_x=30, label_size_y=20, label_pad_x=-0.05, label_pad_y=10, label_rotation_y=0, aspect=1, pad_demo=True, workspace_color="darkred", grid=True, grid_color="grey", tick_color="darkgrey", tick_decimals=4, tick_number_x=12, tick_number_y=12, tick_rotation_x=35, color_bar=True, cb_tick_number=5, cb_pad=0.05, show=True) | [1](https://github.com/alopezrivera/mpl_plotter/blob/master/demo/scripts/line2.py#L13) | [2](https://github.com/alopezrivera/mpl_plotter/blob/master/demo/scripts/line2.py#L21) | | --- | --- | | ![alt text](demo/gallery/2d/medium_line.png "Some customization") | ![alt text](demo/gallery/2d/custom_line.png "Showcase") | ### 4.2 3D Same applies in 3D. | [0](https://github.com/alopezrivera/mpl_plotter/blob/master/demo/scripts/line3.py#L5) | [1](https://github.com/alopezrivera/mpl_plotter/blob/master/demo/scripts/line3.py#L15) | [2](https://github.com/alopezrivera/mpl_plotter/blob/master/demo/scripts/line3.py#L31) | |---|---|---| |![alt text](demo/gallery/3d/basic_line.png "Basic")|![alt text](demo/gallery/3d/medium_line.png "Some customization")|![alt text](demo/gallery/3d/custom_line.png "Showcase")| # 5. Curve comparisons and multiple pane plots `from mpl_plotter.two_d import comparison, panes` ### 5.1 `comparison` Plot any number of curves in a single plot. Axis limits will be set to the maximum and minimum of all your curves. No data will be left out, among other niceties. #### Data input Inputs must match (2 `x`s and 3 `y`s won't work), BUT the following inputs are all valid: | x | y | result | notes | | --- | --- | --- | --- | | array | array | 1 | | | array | [array, array] | 2 | Both `y`s share `x` | | [array, array] | [array, array] | 2 | Each `y` has an `x` | | [n*[array]] | [n*[array]] | n | Each `y` has an `x` | #### Plotting methods You can specify **different plotting methods for each curve in the plot**, a custom one for all curves, or not specify any (defaulting to lines). How? Check the code block below. This is nice as it allows you to crisply combine lines, scatter plots and any other of the MPL Plotter plotting methods. #### Other arguments As to any and all other arguments: - **Singular arguments**: the regular MPL Plotter plotting class arguments. Apply to all curves in the plot. - **Plural arguments**: pass a list of arguments, one for each curve. The result is as you'd imagine. ``` from mpl_plotter.two_d import comparison, line, scatter def f(x, y, **kwargs): line(x, y, line_width=2, **kwargs) def g(x, y, **kwargs): scatter(x, y, marker="D", point_size=10, **kwargs) def h(x, y, **kwargs): scatter(x, y, marker="s", point_size=5, **kwargs) comparison([x, x, x], [u, v, w], [f, g, h], plot_labels=["sin", "cos", "tan"], zorders=[1, 2, 3], colors=['C1', 'C2', 'C3'], alphas=[0.5, 0.5, 1], x_custom_tick_labels=[0, r"$\frac{\pi}{8}$", r"$\frac{\pi}{4}$"], show=show, backend=backend ) ``` ![alt text](demo/gallery/2d/comparison_custom.png "Curve comparison") ### 5.2 `panes` The panes function allows for the plotting of a series of graphs in side-by-side panes. As to data input, the table below applies. It uses the `comparison`, function under the hood so the same input guidelines apply for all other inputs. | x | y | result | notes | | --- | --- | --- | --- | | array | array | 11 | | | array | [array, array] | 12 | Both `y`s share `x` | | [n*[array]] | [n*[array]] | 1n | Each `y` has an `x` | | array | [array, array] | 21 | Both `y`s share `x` | | [array, array] | [array, array] | 21 | Each `y` has an `x` | | array | [n*[array], n*[array]] | 2n | All curves in all (2) panes share a single `x` | | [array, array] | [n*[array], n*[array]] | 2n | All curves in each pane share an `x` | | [n*[array], n*[array]] | [n*[array], n*[array]] | 2n | All curves in all (2) panes have their own `x` | | [n*[array], ... up to m] | [n*[array], ... up to m] | mn | All curves in all panes have their own `x` | ### Code The following plots one curve per pane (3 in total): ``` panes(x, # Horizontal vector [u, v, y], # List of curves to be plotted ["u", "v", "y"], # List of vertical axis labels ["a", "b", "c"] # List of legend labels ) ``` ![alt text](demo/gallery/2d/pane_single.png "Single-curve panes") And the following plots an arbitrary number of curves per pane. As you can see, you just need to input `n` **lists** of `m` curves (where `m`=2 in the example below), and you will get a plot with `n` panes, with `m` curves in each. ``` panes(x, # Horizontal vector [[u, uu], [v, vv], [y, yy]], # List of pairs of curves to be compared ["u", "v", "y"], # List of vertical axis labels ["a", "b"] # List of legend labels ) ``` ![alt text](demo/gallery/2d/pane_comparison.png "Multiple-curve comparison panes") ### Demo Preposterous demonstration to illustrate the **n** panes, **m** curves concept. The code for these is available in `tests/test_panes.py`. ![alt text](demo/gallery/2d/pane_alot.png "There's a lot") ![alt text](demo/gallery/2d/pane_alot_comparison.png "Lots of triplets") # 6. Presets TL;DR: Take a parameter `toml` and forget about function inputs. ### 6.1 Standard presets Standard presets are available to remove overhead. They're tailored for my use cases but you may find them useful anyway. | ![alt text](demo/gallery/2d/preset_publication_scatter.png "Publication preset")| ![alt text](demo/gallery/2d/preset_publication_heatmap.png "Publication preset") | ![alt text](demo/gallery/2d/preset_publication_quiver.png "Publication preset") | ![alt text](demo/gallery/2d/preset_publication_streamline.png "Publication preset") | ![alt text](demo/gallery/2d/preset_publication_fill.png "Publication preset") | ![alt text](demo/gallery/3d/preset_publication_line.png "Publication preset") | ![alt text](demo/gallery/3d/preset_publication_scatter.png "Publication preset") | ![alt text](demo/gallery/3d/preset_publication_surface.png "Publication preset") | | --- | --- | --- | --- | --- | --- | --- | --- | | ![alt text](demo/gallery/2d/preset_precision_scatter.png "Precision preset")| ![alt text](demo/gallery/2d/preset_precision_heatmap.png "Precision preset") | ![alt text](demo/gallery/2d/preset_precision_quiver.png "Precision preset") | ![alt text](demo/gallery/2d/preset_precision_streamline.png "Precision preset") | ![alt text](demo/gallery/2d/preset_precision_fill.png "Precision preset") | ![alt text](demo/gallery/3d/preset_precision_line.png "Precision preset") | ![alt text](demo/gallery/3d/preset_precision_scatter.png "Precision preset") | ![alt text](demo/gallery/3d/preset_precision_surface.png "Precision preset") | #### _Publication_ It is a common mistake to make a figure for a paper with unreadable labels. This preset tries to solve that, generating plots optimized to be printed on a small format, in side-by-side plots or embedded in a column of text. from mpl_plotter.presets.precision import two_d from mpl_plotter.color.schemes import one # Custom colorscheme x = np.linspace(0, 4, 1000) y = np.exp(x) z = abs(np.sin(x)*np.exp(x)) two_d.line(x, z, aspect=0.05, color=one()[-2], show=True) ![alt text](demo/gallery/2d/preset_publication_line.png "Publication preset") #### _Precision_ Made to plot functions large on the screen, with equal x and y scales to avoid skewing the variables, and many ticks to visually inspect a signal. from mpl_plotter.presets.precision import two_d two_d.line(x, z, aspect=0.05, color=one()[-2], show=True) ![alt text](demo/gallery/2d/preset_precision_line.png "Precision preset") ### 6.2 Custom presets Example workflow follows. For further reference check [the preset tests](https://github.com/alopezrivera/mpl_plotter/blob/master/tests/test_presets.py). 1. Import the preset creation function ``` from mpl_plotter.presets import preset ``` 2. Create a preset, either from a plotter, ``` from mpl_plotter.two_d import line _preset = preset(line) ``` or from a dimension. In this case, the preset will contain all common parameters to all plots in 2 or 3 dimensions. ``` _preset = preset(dim=2) ``` The preset is a dictionary. You can edit its parameters as you would expect. However, it is more convenient to 3. Save your preset in a `toml` file. This will yield you a `toml` file containing all parameters for your plot or dimension, allowing you to easily inspect defaults and tailor settings to your liking. You may edit this file as you please, as long as you do not infringe on its syntax. ``` _preset.save('tests/presets/test.toml') ``` 4. Load the file in the same -or a different session. ``` from mpl_plotter.presets import preset _preset = preset.load('tests/presets/test.toml') ``` 5. Import an MPL Plotter preset plotter and load it with your preset ``` from mpl_plotter.presets import two_d _two_d = two_d(preset=_preset) ``` 6. Plot as you wish ``` _two_d.line(show=True) _two_d.scatter(show=True) _two_d.<...> ``` # 7. Matplotlib ### 7.1 Retrieving axes, figures The axis and figure on which each class draws are instance attributes. To retrieve them and continue modifications using standard Matplotlib: from mpl_plotter.two_d import line my_plot = line() ax, fig = my_plot.ax, my_plot.fig With the axis and figure, most Matplotlib functions out there can be used to further modify your plots. ### 7.2 Using Matplotlib's axis tiling Matplotlib allows for subplot composition using `subplot2grid`. This can be used in combination with MPL Plotter: Importantly: - The auxiliary function `figure` (`from mpl_plotter figure`) sets up a figure in a chosen backend. This is convenient, as if the figure is created with `plt.figure()`, only the default non-interactive Matplotlib backend will be available, unless `matplotlib.use()` is specified before importing `pyplot`. ``` from mpl_plotter import figure from mpl_plotter.two_d import line, quiver, streamline, fill_area backend = "Qt5Agg" # None -> regular non-interactive matplotlib output figure(figsize=(10, 10), backend=backend) ax0 = plt.subplot2grid((2, 2), (0, 0), rowspan=1) ax1 = plt.subplot2grid((2, 2), (1, 0), rowspan=1) ax2 = plt.subplot2grid((2, 2), (0, 1), rowspan=1) ax3 = plt.subplot2grid((2, 2), (1, 1), rowspan=1) axes = [ax0, ax1, ax2, ax3] plots = [line, quiver, streamline, fill_area] for i in range(len(plots)): plots[i](ax=axes[i]) plt.show() ``` %package help Summary: Development documents and examples for mpl-plotter Provides: python3-mpl-plotter-doc %description help Two more examples (results in the table below): 1. We can add some customization to make our line look a bit better: line(show=True, pad_demo=True, spines_removed=None) Our line has now some margins to breathe while the ticks are placed at the maximum and minimums of our curve, and no spines are removed. 2. Lastly, an example using some of the parameters you can change: line(norm=True, line_width=4, title="Custom Line", title_font="Pump Triline", title_size=40, title_color="orange", label_x="x", label_y="$\Psi$", label_size_x=30, label_size_y=20, label_pad_x=-0.05, label_pad_y=10, label_rotation_y=0, aspect=1, pad_demo=True, workspace_color="darkred", grid=True, grid_color="grey", tick_color="darkgrey", tick_decimals=4, tick_number_x=12, tick_number_y=12, tick_rotation_x=35, color_bar=True, cb_tick_number=5, cb_pad=0.05, show=True) | [1](https://github.com/alopezrivera/mpl_plotter/blob/master/demo/scripts/line2.py#L13) | [2](https://github.com/alopezrivera/mpl_plotter/blob/master/demo/scripts/line2.py#L21) | | --- | --- | | ![alt text](demo/gallery/2d/medium_line.png "Some customization") | ![alt text](demo/gallery/2d/custom_line.png "Showcase") | ### 4.2 3D Same applies in 3D. | [0](https://github.com/alopezrivera/mpl_plotter/blob/master/demo/scripts/line3.py#L5) | [1](https://github.com/alopezrivera/mpl_plotter/blob/master/demo/scripts/line3.py#L15) | [2](https://github.com/alopezrivera/mpl_plotter/blob/master/demo/scripts/line3.py#L31) | |---|---|---| |![alt text](demo/gallery/3d/basic_line.png "Basic")|![alt text](demo/gallery/3d/medium_line.png "Some customization")|![alt text](demo/gallery/3d/custom_line.png "Showcase")| # 5. Curve comparisons and multiple pane plots `from mpl_plotter.two_d import comparison, panes` ### 5.1 `comparison` Plot any number of curves in a single plot. Axis limits will be set to the maximum and minimum of all your curves. No data will be left out, among other niceties. #### Data input Inputs must match (2 `x`s and 3 `y`s won't work), BUT the following inputs are all valid: | x | y | result | notes | | --- | --- | --- | --- | | array | array | 1 | | | array | [array, array] | 2 | Both `y`s share `x` | | [array, array] | [array, array] | 2 | Each `y` has an `x` | | [n*[array]] | [n*[array]] | n | Each `y` has an `x` | #### Plotting methods You can specify **different plotting methods for each curve in the plot**, a custom one for all curves, or not specify any (defaulting to lines). How? Check the code block below. This is nice as it allows you to crisply combine lines, scatter plots and any other of the MPL Plotter plotting methods. #### Other arguments As to any and all other arguments: - **Singular arguments**: the regular MPL Plotter plotting class arguments. Apply to all curves in the plot. - **Plural arguments**: pass a list of arguments, one for each curve. The result is as you'd imagine. ``` from mpl_plotter.two_d import comparison, line, scatter def f(x, y, **kwargs): line(x, y, line_width=2, **kwargs) def g(x, y, **kwargs): scatter(x, y, marker="D", point_size=10, **kwargs) def h(x, y, **kwargs): scatter(x, y, marker="s", point_size=5, **kwargs) comparison([x, x, x], [u, v, w], [f, g, h], plot_labels=["sin", "cos", "tan"], zorders=[1, 2, 3], colors=['C1', 'C2', 'C3'], alphas=[0.5, 0.5, 1], x_custom_tick_labels=[0, r"$\frac{\pi}{8}$", r"$\frac{\pi}{4}$"], show=show, backend=backend ) ``` ![alt text](demo/gallery/2d/comparison_custom.png "Curve comparison") ### 5.2 `panes` The panes function allows for the plotting of a series of graphs in side-by-side panes. As to data input, the table below applies. It uses the `comparison`, function under the hood so the same input guidelines apply for all other inputs. | x | y | result | notes | | --- | --- | --- | --- | | array | array | 11 | | | array | [array, array] | 12 | Both `y`s share `x` | | [n*[array]] | [n*[array]] | 1n | Each `y` has an `x` | | array | [array, array] | 21 | Both `y`s share `x` | | [array, array] | [array, array] | 21 | Each `y` has an `x` | | array | [n*[array], n*[array]] | 2n | All curves in all (2) panes share a single `x` | | [array, array] | [n*[array], n*[array]] | 2n | All curves in each pane share an `x` | | [n*[array], n*[array]] | [n*[array], n*[array]] | 2n | All curves in all (2) panes have their own `x` | | [n*[array], ... up to m] | [n*[array], ... up to m] | mn | All curves in all panes have their own `x` | ### Code The following plots one curve per pane (3 in total): ``` panes(x, # Horizontal vector [u, v, y], # List of curves to be plotted ["u", "v", "y"], # List of vertical axis labels ["a", "b", "c"] # List of legend labels ) ``` ![alt text](demo/gallery/2d/pane_single.png "Single-curve panes") And the following plots an arbitrary number of curves per pane. As you can see, you just need to input `n` **lists** of `m` curves (where `m`=2 in the example below), and you will get a plot with `n` panes, with `m` curves in each. ``` panes(x, # Horizontal vector [[u, uu], [v, vv], [y, yy]], # List of pairs of curves to be compared ["u", "v", "y"], # List of vertical axis labels ["a", "b"] # List of legend labels ) ``` ![alt text](demo/gallery/2d/pane_comparison.png "Multiple-curve comparison panes") ### Demo Preposterous demonstration to illustrate the **n** panes, **m** curves concept. The code for these is available in `tests/test_panes.py`. ![alt text](demo/gallery/2d/pane_alot.png "There's a lot") ![alt text](demo/gallery/2d/pane_alot_comparison.png "Lots of triplets") # 6. Presets TL;DR: Take a parameter `toml` and forget about function inputs. ### 6.1 Standard presets Standard presets are available to remove overhead. They're tailored for my use cases but you may find them useful anyway. | ![alt text](demo/gallery/2d/preset_publication_scatter.png "Publication preset")| ![alt text](demo/gallery/2d/preset_publication_heatmap.png "Publication preset") | ![alt text](demo/gallery/2d/preset_publication_quiver.png "Publication preset") | ![alt text](demo/gallery/2d/preset_publication_streamline.png "Publication preset") | ![alt text](demo/gallery/2d/preset_publication_fill.png "Publication preset") | ![alt text](demo/gallery/3d/preset_publication_line.png "Publication preset") | ![alt text](demo/gallery/3d/preset_publication_scatter.png "Publication preset") | ![alt text](demo/gallery/3d/preset_publication_surface.png "Publication preset") | | --- | --- | --- | --- | --- | --- | --- | --- | | ![alt text](demo/gallery/2d/preset_precision_scatter.png "Precision preset")| ![alt text](demo/gallery/2d/preset_precision_heatmap.png "Precision preset") | ![alt text](demo/gallery/2d/preset_precision_quiver.png "Precision preset") | ![alt text](demo/gallery/2d/preset_precision_streamline.png "Precision preset") | ![alt text](demo/gallery/2d/preset_precision_fill.png "Precision preset") | ![alt text](demo/gallery/3d/preset_precision_line.png "Precision preset") | ![alt text](demo/gallery/3d/preset_precision_scatter.png "Precision preset") | ![alt text](demo/gallery/3d/preset_precision_surface.png "Precision preset") | #### _Publication_ It is a common mistake to make a figure for a paper with unreadable labels. This preset tries to solve that, generating plots optimized to be printed on a small format, in side-by-side plots or embedded in a column of text. from mpl_plotter.presets.precision import two_d from mpl_plotter.color.schemes import one # Custom colorscheme x = np.linspace(0, 4, 1000) y = np.exp(x) z = abs(np.sin(x)*np.exp(x)) two_d.line(x, z, aspect=0.05, color=one()[-2], show=True) ![alt text](demo/gallery/2d/preset_publication_line.png "Publication preset") #### _Precision_ Made to plot functions large on the screen, with equal x and y scales to avoid skewing the variables, and many ticks to visually inspect a signal. from mpl_plotter.presets.precision import two_d two_d.line(x, z, aspect=0.05, color=one()[-2], show=True) ![alt text](demo/gallery/2d/preset_precision_line.png "Precision preset") ### 6.2 Custom presets Example workflow follows. For further reference check [the preset tests](https://github.com/alopezrivera/mpl_plotter/blob/master/tests/test_presets.py). 1. Import the preset creation function ``` from mpl_plotter.presets import preset ``` 2. Create a preset, either from a plotter, ``` from mpl_plotter.two_d import line _preset = preset(line) ``` or from a dimension. In this case, the preset will contain all common parameters to all plots in 2 or 3 dimensions. ``` _preset = preset(dim=2) ``` The preset is a dictionary. You can edit its parameters as you would expect. However, it is more convenient to 3. Save your preset in a `toml` file. This will yield you a `toml` file containing all parameters for your plot or dimension, allowing you to easily inspect defaults and tailor settings to your liking. You may edit this file as you please, as long as you do not infringe on its syntax. ``` _preset.save('tests/presets/test.toml') ``` 4. Load the file in the same -or a different session. ``` from mpl_plotter.presets import preset _preset = preset.load('tests/presets/test.toml') ``` 5. Import an MPL Plotter preset plotter and load it with your preset ``` from mpl_plotter.presets import two_d _two_d = two_d(preset=_preset) ``` 6. Plot as you wish ``` _two_d.line(show=True) _two_d.scatter(show=True) _two_d.<...> ``` # 7. Matplotlib ### 7.1 Retrieving axes, figures The axis and figure on which each class draws are instance attributes. To retrieve them and continue modifications using standard Matplotlib: from mpl_plotter.two_d import line my_plot = line() ax, fig = my_plot.ax, my_plot.fig With the axis and figure, most Matplotlib functions out there can be used to further modify your plots. ### 7.2 Using Matplotlib's axis tiling Matplotlib allows for subplot composition using `subplot2grid`. This can be used in combination with MPL Plotter: Importantly: - The auxiliary function `figure` (`from mpl_plotter figure`) sets up a figure in a chosen backend. This is convenient, as if the figure is created with `plt.figure()`, only the default non-interactive Matplotlib backend will be available, unless `matplotlib.use()` is specified before importing `pyplot`. ``` from mpl_plotter import figure from mpl_plotter.two_d import line, quiver, streamline, fill_area backend = "Qt5Agg" # None -> regular non-interactive matplotlib output figure(figsize=(10, 10), backend=backend) ax0 = plt.subplot2grid((2, 2), (0, 0), rowspan=1) ax1 = plt.subplot2grid((2, 2), (1, 0), rowspan=1) ax2 = plt.subplot2grid((2, 2), (0, 1), rowspan=1) ax3 = plt.subplot2grid((2, 2), (1, 1), rowspan=1) axes = [ax0, ax1, ax2, ax3] plots = [line, quiver, streamline, fill_area] for i in range(len(plots)): plots[i](ax=axes[i]) plt.show() ``` %prep %autosetup -n mpl-plotter-5.5.0 %build %py3_build %install %py3_install install -d -m755 %{buildroot}/%{_pkgdocdir} if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi pushd %{buildroot} if [ -d usr/lib ]; then find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst fi if [ -d usr/lib64 ]; then find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst fi if [ -d usr/bin ]; then find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst fi if [ -d usr/sbin ]; then find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst fi touch doclist.lst if [ -d usr/share/man ]; then find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst fi popd mv %{buildroot}/filelist.lst . mv %{buildroot}/doclist.lst . %files -n python3-mpl-plotter -f filelist.lst %dir %{python3_sitelib}/* %files help -f doclist.lst %{_docdir}/* %changelog * Mon May 15 2023 Python_Bot - 5.5.0-1 - Package Spec generated