Skip to content

2D and 3D Plots

Matplotlib-type Plots

Plotting functions using via matplotlib.

Examples:

Python Console Session
>>> from pathlib import Path
>>> import numpy as np
>>> from umf.images.diagrams import ClassicPlot
>>> from umf.meta.plots import GraphSettings
>>> x = np.linspace(-10, 10, 100)
>>> y = np.linspace(-10, 10, 100)
>>> X, Y = np.meshgrid(x, y)
>>> Z = X ** 2 + Y ** 2
>>> plot = ClassicPlot(X, Y, Z, settings=GraphSettings(axis=["x", "y", "z"]))
>>> plot.plot_3d()
>>> ClassicPlot.plot_save(plot.plot_return, Path("ClassicPlot_3d.png"))
>>> plot.plot_contour()
>>> ClassicPlot.plot_save(plot.plot_return, Path("ClassicPlot_contour.png"))
>>> plot.plot_surface()
>>> ClassicPlot.plot_save(plot.plot_return, Path("ClassicPlot_surface.png"))
>>> plot.plot_dashboard()
>>> ClassicPlot.plot_save(plot.plot_return, Path("ClassicPlot_dashboard.png"))
>>> plot.plot_close()

Examples:

Python Console Session
>>> from pathlib import Path
>>> import numpy as np
>>> from umf.images.diagrams import ClassicPlot
>>> from umf.meta.plots import GraphSettings
>>> from umf.meta.plots import GIFSettings
>>> from umf.functions.optimization.special import GoldsteinPriceFunction
>>> # Start with a simple plot
>>> x = np.linspace(-2, 2, 100)
>>> y = np.linspace(-2, 2, 100)
>>> X, Y = np.meshgrid(x, y)
>>> Z = GoldsteinPriceFunction(X, Y).__eval__
>>> plot = ClassicPlot(
...     X,
...     Y,
...     Z,
...     settings=GraphSettings(axis=["x", "y", "z"]),
... )
>>> plot.plot_surface()
>>> # Now only zoom
>>> plot.plot_save_gif(
...     fig=plot.plot_return,
...     ax_fig=plot.ax_return,
...     fname=Path("GoldsteinPriceFunction_zoom.gif"),
...     settings=GIFSettings(rotate=False),
...     savefig_kwargs={"transparent": True},
... )
>>> # Now only rotate
>>> plot.plot_save_gif(
...     fig=plot.plot_return,
...     ax_fig=plot.ax_return,
...     fname=Path("GoldsteinPriceFunction_rotate.gif"),
...     settings=GIFSettings(zoom=False),
...     savefig_kwargs={"transparent": True},
... )
>>> # Now only zoom and rotate
>>> plot.plot_save_gif(
...     fig=plot.plot_return,
...     ax_fig=plot.ax_return,
...     fname=Path("GoldsteinPriceFunction_all.gif"),
...     settings=GIFSettings(),
...     savefig_kwargs={"transparent": True},
... )
>>> plot.plot_close()

Examples:

Python Console Session
>>> from pathlib import Path
>>> import numpy as np
>>> from umf.images.diagrams import ClassicPlot
>>> from umf.meta.plots import GraphSettings
>>> from umf.functions.distributions.continuous_semi_infinite_interval import (
...    RayleighDistribution,
... )
>>> x = np.linspace(0, 10, 100)
>>> y_sigma_1 = RayleighDistribution(x, sigma=1).__eval__
>>> y_sigma_2 = RayleighDistribution(x, sigma=2).__eval__
>>> y_sigma_3 = RayleighDistribution(x, sigma=3).__eval__
>>> plot = ClassicPlot(
...     np.array([x, y_sigma_1]),
...     np.array([x, y_sigma_2]),
...     np.array([x, y_sigma_3]),
...     settings=GraphSettings(
...         axis=["x", r"$f(x)$"],
...         title="Rayleigh Distribution",
...     ),
... )
>>> plot.plot_series(label=[r"$\sigma=1$", r"$\sigma=2$", r"$\sigma=3$"])
>>> ClassicPlot.plot_save(plot.plot_return, Path("ClassicPlot_series.png"))

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which can be one, two, three, or higher dimensional.

()
settings GraphSettings

Settings for the graph. Defaults to None.

None
**kwargs dict[str, Any]

Additional keyword arguments to pass to the plot function.

{}
Types Matplotlib-type Plots
3D-Plot ClassicPlot3d
Contour-Plot ClassicPlotContour
Surface-Plot ClassicPlotSurface
Dashboard-Plot coming soon
2D-Plot ClassicPlotSeries

Plotly-type Plots

Plotting functions using via plotly.

Examples:

Python Console Session
>>> from pathlib import Path
>>> import numpy as np
>>> from umf.images.diagrams import PlotlyPlot
>>> from umf.meta.plots import GraphSettings
>>> x = np.linspace(-10, 10, 100)
>>> y = np.linspace(-10, 10, 100)
>>> X, Y = np.meshgrid(x, y)
>>> Z = X ** 2 + Y ** 2
>>> plot = PlotlyPlot(X, Y, Z, settings=GraphSettings(axis=["x", "y", "z"]))
>>> plot.plot_3d()
>>> PlotlyPlot.plot_save(plot.plot_return, Path("PlotlyPlot_3d.png"))
>>> plot.plot_contour()
>>> PlotlyPlot.plot_save(plot.plot_return, Path("PlotlyPlot_contour.png"))
>>> plot.plot_surface()
>>> PlotlyPlot.plot_save(plot.plot_return, Path("PlotlyPlot_surface.png"))

Examples:

Python Console Session
>>> from pathlib import Path
>>> import numpy as np
>>> from umf.images.diagrams import PlotlyPlot
>>> from umf.meta.plots import GraphSettings
>>> from umf.functions.distributions.continuous_semi_infinite_interval import (
...    RayleighDistribution,
... )
>>> x = np.linspace(0, 10, 100)
>>> y_sigma_1 = RayleighDistribution(x, sigma=1).__eval__
>>> y_sigma_2 = RayleighDistribution(x, sigma=2).__eval__
>>> y_sigma_3 = RayleighDistribution(x, sigma=3).__eval__
>>> plot = PlotlyPlot(
...     np.array([x, y_sigma_1]),
...     np.array([x, y_sigma_2]),
...     np.array([x, y_sigma_3]),
...     settings=GraphSettings(
...         axis=["x", r"$f(x)$"],
...         title="Rayleigh Distribution",
...     ),
... )
>>> plot.plot_series(label=[r"$\sigma=1$", r"$\sigma=2$", r"$\sigma=3$"])
>>> PlotlyPlot.plot_save(plot.plot_return, Path("PlotlyPlot_series.png"))

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which can be one, two, three, or higher dimensional.

()
settings GraphSettings

Settings for the graph. Defaults to None.

None
**kwargs dict[str, Any]

Keyword arguments for the plot.

{}
Types Plotly-type Plots
3D-Plot PlotlyPlot3d
Contour-Plot PlotlyPlotContour
Surface-Plot PlotlyPlotSurface
Dashboard-Plot coming soon
2D-Plot PlotlyPlotSeries