#!/usr/bin/env python
# coding: utf-8
# nazvy proměnných jsou v angličtině
# Ale komenty teda ne)
import matplotlib
# direct use of matplotlib.fugure requires
# FigureManagerBase and managing of event loop
#import matplotlib.figure as mfigure
#č takže budeme i nadale pokorně použivat pyplot
import matplotlib.pyplot as plt
matplotlib.rcParams['mathtext.fontset'] = 'cm' # Computer Modern (TeX)
matplotlib.rcParams['font.family'] = 'STIXGeneral'
matplotlib.rcParams['savefig.dpi'] = 300
matplotlib.rcParams['savefig.bbox'] = 'tight'
matplotlib.rcParams['savefig.pad_inches'] = 0
matplotlib.rcParams['axes.linewidth'] = 1
matplotlib.rcParams['font.size'] = 8
# Show-functions
# Specially for qt_plot.
# Requires an event loop already running
tight_layout=True
def show_ax(ax_function, sample_box, space='R'):
fig = plt.figure(figsize=(9/2.54, 9/2.54), tight_layout=True)
ax = fig.add_subplot(111)
ax.space = space
ax.sample_box = sample_box
ax_function(ax)
fig.show()
def show_ax3d(ax3d_function, sample_box, space='R'):
fig = plt.figure(figsize=(9/2.54, 9/2.54), tight_layout=True)
ax = fig.add_subplot(111, projection='3d')
ax.space = space
ax.sample_box = sample_box
ax3d_function(ax)
fig.show()
def show_fig(fig_function, *args, **kwargs):
fig = plt.figure(figsize=(9/2.54, 9/2.54), tight_layout=True)
fig_function(fig, *args, **kwargs)
fig.show()
#
#č předělat na normální ploty
def subplot3D(sample_box, ax3d, space='R'):
Fails = getattr(sample_box.failure_samples, space)
Succeses = getattr(sample_box.success_samples, space)
xyz = [0,1,2]
ax3d.scatter(Fails[:,xyz[0]], Fails[:,xyz[1]], Fails[:,xyz[2]], c='r', marker='.')
ax3d.scatter(Succeses[:,xyz[0]], Succeses[:,xyz[1]], Succeses[:,xyz[2]], c='g', marker='.')
ax3d.set_xlabel('X')
ax3d.set_ylabel('Y')
ax3d.set_zlabel('Z')
def plot3D(sample_box, space='R', filename='', format='pdf'):
if not filename:
filename = 'store/%s_%s_%s_plot3D'%(sample_box.gm_signature, space, sample_box.nsim)
fig = plt.figure()
ax3d = fig.add_subplot(111, projection='3d')
subplot3D(sample_box, ax3d, space)
try: # jen pro formu zkusíme, vždyť musí funkce formálně něco dělat, žejo?
fig.savefig(filename + "." + format)#, dpi=300)
except:
pass # nic se neděje
# vracím plt místo figury, protože nechcem sa trapiť ivent lupem
# return plt insted of just fig to bypass event loop issues
return plt.show()
# nikdo mi neuvěří, že by tohle postačílo a nebylo by nutné tohlensto furt úpravovat
def plot2D(sample_box, space='R', candidates=False, filename=None, format='pdf'):
if filename is None:
try:
filename = sample_box.filename
except:
filename = 'store/%s_%s_%s_plot2D'%(sample_box.gm_signature, space, sample_box.nsim)
fig = plt.figure()
ax = fig.add_subplot(111)
ax.space = space
ax.sample_box = sample_box
mart.setup(ax)
mart.curly(ax)
mart.plot_boundaries(ax, linewidth=0.7)
mart.scatter_points(ax)
try:
mart.triplot(ax, color="grey", linewidth=0.4)
except:
pass
if candidates:
#č ax.scatter posílá parameter cmap Collections třídě.
#č Třída mimo jiného dědí cm.ScalarMappable,
#č která inicializaci deleguje funkci cm.get_cmap() ve (svém) modulu cm.
# cmap='viridis_r' #cmap='plasma',
mart.scatter_candidates(ax, s=5, marker='.', cmap='plasma_r',\
alpha=None, linewidths=None, edgecolors=None, plotnonfinite=False)
mart.plot_the_best_candidate(ax, "^", color='#3D0D5B')
try: # jen pro formu zkusíme, vždyť musí funkce formálně něco dělat, žejo?
fig.savefig(filename + "." + format, dpi=300)
except:
pass # nic se neděje
# vracím plt místo figury, protože nechcem sa trapiť ivent lupem
# return plt insted of just fig to bypass event loop issues
return plt.show()