Module mpl_plotter.panes
Expand source code
import numpy as np
import matplotlib as mpl
from mpl_plotter.setup import figure
from mpl_plotter.color.schemes import one
from mpl_plotter.presets.custom import two_d
from alexandria.logic import if_none
from alexandria.shell import print_color
from alexandria.data_structs.array import lists_to_ndarrays, internal_array_shape
def n_pane_single(x, y,
labels=None, legend_labels=None,
filename=None, where_does_this_go=None,
**kwargs):
# Regular defaults
backend = kwargs.pop('backend', None) # Setup
legend_loc = kwargs.pop('legend_loc', (0.875, 0.55)) # Legend
show = kwargs.pop('show', False) # Display
save = kwargs.pop('save', False)
legend = kwargs.pop('legend', True if not isinstance(legend_labels, type(None)) else True) # Legend
# Figure setup
fig = figure((5*len(y), 3.5), backend=backend)
import matplotlib.pyplot as plt
# Plot
for i in range(len(y)):
ax_transient = plt.subplot2grid((1, len(y)), (0, i), rowspan=1, colspan=1)
if i < (len(y) - 1):
line(x=x, y=y[i], color=one()[i], ax=ax_transient, fig=fig,
y_label=labels[i] if not isinstance(labels, type(None)) else None,
plot_label=legend_labels[i] if not isinstance(legend_labels, type(None)) else None,
backend=backend)
else:
line(x=x, y=y[i], color=one()[i], ax=ax_transient, fig=fig,
y_label=labels[i] if not isinstance(labels, type(None)) else None,
legend=True if not isinstance(legend_labels, type(None)) else False,
plot_label=legend_labels[i] if not isinstance(legend_labels, type(None)) else None,
legend_loc=legend_loc,
backend=backend,
**kwargs)
plt.subplots_adjust(left=0.1, right=0.85, wspace=0.6, hspace=0.35)
if not isinstance(filename, type(None)) and not isinstance(where_does_this_go, type(None)):
plt.savefig(f"{where_does_this_go}/{filename}.pdf")
plt.show()
if show:
plt.show()
if save:
filename = input("Filename:") if isinstance(filename, type(None)) \
else filename
where_does_this_go = input("Destination directory:") if isinstance(where_does_this_go, type(None)) \
else where_does_this_go
try:
plt.savefig(f"{where_does_this_go}/{filename}.pdf",
bbox_extra_artists=legend,
)
except FileNotFoundError:
print_color("Destination directory does not exist. Destination directory:", "blue")
where_does_this_go = input()
plt.savefig(f"{where_does_this_go}/{filename}.pdf",
bbox_extra_artists=legend,
)
if show:
plt.show()
def n_pane_comparison(t, y,
axis_labels=None, legend_labels=None,
zorders=None, colors=None, alphas=None,
filename=None, where_does_this_go=None,
**kwargs):
# Input check
t, y = lists_to_ndarrays(t, y)
t = cls.comparison_input_match(t, y)
# Special parameters
zorders = if_none(zorders, np.arange(len(y) + 1, 0, -1))
colors = if_none(colors, [one()[n] for n in range(len(y))])
alphas = if_none(alphas, np.ones(len(y)))
# Regular defaults
backend = kwargs.pop('backend', None) # Setup
legend_loc = kwargs.pop('legend_loc', (0.875, 0.55)) # Legend
show = kwargs.pop('show', False) # Display
save = kwargs.pop('save', False)
# Figure setup
fig = figure((5 * len(y), 3.5), backend=backend)
import matplotlib.pyplot as plt
# Plot
for i in range(len(y)):
ax_transient = plt.subplot2grid((1, len(y)), (0, i), rowspan=1, colspan=1)
if i < (len(y) - 1):
cls.comparison([t[i][n] for n in range(len(y[1]))], [y[i][n] for n in range(len(y[1]))],
ax=ax_transient, fig=fig, backend=backend,
y_label=axis_labels[i] if not isinstance(axis_labels, type(None)) else None,
zorders=zorders, colors=colors, alphas=alphas,
legend=False
)
else:
cls.comparison([t[i][n] for n in range(len(y[1]))], [y[i][n] for n in range(len(y[1]))],
ax=ax_transient, fig=fig, backend=backend,
y_label=axis_labels[i] if not isinstance(axis_labels, type(None)) else None,
zorders=zorders, colors=colors, alphas=alphas,
plot_labels=legend_labels,
legend=True if not isinstance(legend_labels, type(None)) else False,
legend_loc=legend_loc,
**kwargs
)
plt.subplots_adjust(left=0.1, right=0.85, wspace=0.6, hspace=0.35)
legend = (c for c in ax_transient.get_children() if isinstance(c, mpl.legend.Legend))
if save:
filename = input("Filename:") if isinstance(filename, type(None)) \
else filename
where_does_this_go = input("Destination directory:") if isinstance(where_does_this_go, type(None)) \
else where_does_this_go
try:
plt.savefig(f"{where_does_this_go}/{filename}.pdf",
bbox_extra_artists=legend,
)
except FileNotFoundError:
print_color("Destination directory does not exist. Destination directory:", "blue")
where_does_this_go = input()
plt.savefig(f"{where_does_this_go}/{filename}.pdf",
bbox_extra_artists=legend,
)
if show:
plt.show()
Functions
def n_pane_comparison(t, y, axis_labels=None, legend_labels=None, zorders=None, colors=None, alphas=None, filename=None, where_does_this_go=None, **kwargs)
-
Expand source code
def n_pane_comparison(t, y, axis_labels=None, legend_labels=None, zorders=None, colors=None, alphas=None, filename=None, where_does_this_go=None, **kwargs): # Input check t, y = lists_to_ndarrays(t, y) t = cls.comparison_input_match(t, y) # Special parameters zorders = if_none(zorders, np.arange(len(y) + 1, 0, -1)) colors = if_none(colors, [one()[n] for n in range(len(y))]) alphas = if_none(alphas, np.ones(len(y))) # Regular defaults backend = kwargs.pop('backend', None) # Setup legend_loc = kwargs.pop('legend_loc', (0.875, 0.55)) # Legend show = kwargs.pop('show', False) # Display save = kwargs.pop('save', False) # Figure setup fig = figure((5 * len(y), 3.5), backend=backend) import matplotlib.pyplot as plt # Plot for i in range(len(y)): ax_transient = plt.subplot2grid((1, len(y)), (0, i), rowspan=1, colspan=1) if i < (len(y) - 1): cls.comparison([t[i][n] for n in range(len(y[1]))], [y[i][n] for n in range(len(y[1]))], ax=ax_transient, fig=fig, backend=backend, y_label=axis_labels[i] if not isinstance(axis_labels, type(None)) else None, zorders=zorders, colors=colors, alphas=alphas, legend=False ) else: cls.comparison([t[i][n] for n in range(len(y[1]))], [y[i][n] for n in range(len(y[1]))], ax=ax_transient, fig=fig, backend=backend, y_label=axis_labels[i] if not isinstance(axis_labels, type(None)) else None, zorders=zorders, colors=colors, alphas=alphas, plot_labels=legend_labels, legend=True if not isinstance(legend_labels, type(None)) else False, legend_loc=legend_loc, **kwargs ) plt.subplots_adjust(left=0.1, right=0.85, wspace=0.6, hspace=0.35) legend = (c for c in ax_transient.get_children() if isinstance(c, mpl.legend.Legend)) if save: filename = input("Filename:") if isinstance(filename, type(None)) \ else filename where_does_this_go = input("Destination directory:") if isinstance(where_does_this_go, type(None)) \ else where_does_this_go try: plt.savefig(f"{where_does_this_go}/{filename}.pdf", bbox_extra_artists=legend, ) except FileNotFoundError: print_color("Destination directory does not exist. Destination directory:", "blue") where_does_this_go = input() plt.savefig(f"{where_does_this_go}/{filename}.pdf", bbox_extra_artists=legend, ) if show: plt.show()
def n_pane_single(x, y, labels=None, legend_labels=None, filename=None, where_does_this_go=None, **kwargs)
-
Expand source code
def n_pane_single(x, y, labels=None, legend_labels=None, filename=None, where_does_this_go=None, **kwargs): # Regular defaults backend = kwargs.pop('backend', None) # Setup legend_loc = kwargs.pop('legend_loc', (0.875, 0.55)) # Legend show = kwargs.pop('show', False) # Display save = kwargs.pop('save', False) legend = kwargs.pop('legend', True if not isinstance(legend_labels, type(None)) else True) # Legend # Figure setup fig = figure((5*len(y), 3.5), backend=backend) import matplotlib.pyplot as plt # Plot for i in range(len(y)): ax_transient = plt.subplot2grid((1, len(y)), (0, i), rowspan=1, colspan=1) if i < (len(y) - 1): line(x=x, y=y[i], color=one()[i], ax=ax_transient, fig=fig, y_label=labels[i] if not isinstance(labels, type(None)) else None, plot_label=legend_labels[i] if not isinstance(legend_labels, type(None)) else None, backend=backend) else: line(x=x, y=y[i], color=one()[i], ax=ax_transient, fig=fig, y_label=labels[i] if not isinstance(labels, type(None)) else None, legend=True if not isinstance(legend_labels, type(None)) else False, plot_label=legend_labels[i] if not isinstance(legend_labels, type(None)) else None, legend_loc=legend_loc, backend=backend, **kwargs) plt.subplots_adjust(left=0.1, right=0.85, wspace=0.6, hspace=0.35) if not isinstance(filename, type(None)) and not isinstance(where_does_this_go, type(None)): plt.savefig(f"{where_does_this_go}/{filename}.pdf") plt.show() if show: plt.show() if save: filename = input("Filename:") if isinstance(filename, type(None)) \ else filename where_does_this_go = input("Destination directory:") if isinstance(where_does_this_go, type(None)) \ else where_does_this_go try: plt.savefig(f"{where_does_this_go}/{filename}.pdf", bbox_extra_artists=legend, ) except FileNotFoundError: print_color("Destination directory does not exist. Destination directory:", "blue") where_does_this_go = input() plt.savefig(f"{where_does_this_go}/{filename}.pdf", bbox_extra_artists=legend, ) if show: plt.show()