diff options
| author | CoprDistGit <infra@openeuler.org> | 2023-05-15 06:07:53 +0000 |
|---|---|---|
| committer | CoprDistGit <infra@openeuler.org> | 2023-05-15 06:07:53 +0000 |
| commit | afb8991aeed357f1808e8a750308d9e1e452e866 (patch) | |
| tree | 7a943cace71eee19144e02903e59dad8656c50b1 | |
| parent | ce1a2d35081417a706caba8e7e6e732519fb00cc (diff) | |
automatic import of python-mpl-plotter
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | python-mpl-plotter.spec | 693 | ||||
| -rw-r--r-- | sources | 1 |
3 files changed, 695 insertions, 0 deletions
@@ -0,0 +1 @@ +/mpl_plotter-5.5.0.tar.gz diff --git a/python-mpl-plotter.spec b/python-mpl-plotter.spec new file mode 100644 index 0000000..10952f1 --- /dev/null +++ b/python-mpl-plotter.spec @@ -0,0 +1,693 @@ +%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) | +| --- | --- | +|  |  | +### 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) | +|---|---|---| +|||| +# 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 + ) +``` + +### 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 + ) +``` + +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 + ) +``` + +### Demo +Preposterous demonstration to illustrate the **n** panes, **m** curves concept. The code for these is +available in `tests/test_panes.py`. + + +# 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. +| |  |  |  |  |  |  |  | +| --- | --- | --- | --- | --- | --- | --- | --- | +| |  |  |  |  |  |  |  | +#### _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) + +#### _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) + +### 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(<backend>)` 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) | +| --- | --- | +|  |  | +### 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) | +|---|---|---| +|||| +# 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 + ) +``` + +### 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 + ) +``` + +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 + ) +``` + +### Demo +Preposterous demonstration to illustrate the **n** panes, **m** curves concept. The code for these is +available in `tests/test_panes.py`. + + +# 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. +| |  |  |  |  |  |  |  | +| --- | --- | --- | --- | --- | --- | --- | --- | +| |  |  |  |  |  |  |  | +#### _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) + +#### _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) + +### 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(<backend>)` 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) | +| --- | --- | +|  |  | +### 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) | +|---|---|---| +|||| +# 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 + ) +``` + +### 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 + ) +``` + +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 + ) +``` + +### Demo +Preposterous demonstration to illustrate the **n** panes, **m** curves concept. The code for these is +available in `tests/test_panes.py`. + + +# 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. +| |  |  |  |  |  |  |  | +| --- | --- | --- | --- | --- | --- | --- | --- | +| |  |  |  |  |  |  |  | +#### _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) + +#### _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) + +### 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(<backend>)` 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 <Python_Bot@openeuler.org> - 5.5.0-1 +- Package Spec generated @@ -0,0 +1 @@ +110f4bb04df91c50008bca5a946a035e mpl_plotter-5.5.0.tar.gz |
