def get_cache_dir(): cache_dir = os.path.join(_get_configdir(), 'test_cache') if not os.path.exists(cache_dir): try: os.makedirs(cache_dir) except IOError: return None if not os.access(cache_dir, os.W_OK): return None return cache_dir
def get_cache_dir(): configdir = _get_configdir() if configdir is None: raise RuntimeError('Could not find a suitable configuration directory') cache_dir = os.path.join(configdir, 'test_cache') if not os.path.exists(cache_dir): try: os.makedirs(cache_dir) except IOError: return None if not os.access(cache_dir, os.W_OK): return None return cache_dir
``library`` A dictionary of style names and matplotlib settings. """ import os import re import contextlib import matplotlib as mpl from matplotlib import cbook from matplotlib import rc_params_from_file __all__ = ['use', 'context', 'available', 'library', 'reload_library'] BASE_LIBRARY_PATH = os.path.join(mpl.get_data_path(), 'stylelib') # Users may want multiple library paths, so store a list of paths. USER_LIBRARY_PATHS = [os.path.join(mpl._get_configdir(), 'stylelib')] STYLE_EXTENSION = 'mplstyle' STYLE_FILE_PATTERN = re.compile('([\S]+).%s$' % STYLE_EXTENSION) def is_style_file(filename): """Return True if the filename looks like a style file.""" return STYLE_FILE_PATTERN.match(filename) is not None def use(style): """Use matplotlib style settings from a style specification. Parameters ---------- style : str, dict, or list
import os import re import contextlib import warnings import matplotlib as mpl from matplotlib import cbook from matplotlib import rc_params_from_file, rcParamsDefault __all__ = ['use', 'context', 'available', 'library', 'reload_library'] BASE_LIBRARY_PATH = os.path.join(mpl.get_data_path(), 'stylelib') # Users may want multiple library paths, so store a list of paths. USER_LIBRARY_PATHS = [os.path.join(mpl._get_configdir(), 'stylelib')] STYLE_EXTENSION = 'mplstyle' STYLE_FILE_PATTERN = re.compile(r'([\S]+).%s$' % STYLE_EXTENSION) # A list of rcParams that should not be applied from styles STYLE_BLACKLIST = { 'interactive', 'backend', 'backend.qt4', 'webagg.port', 'webagg.port_retries', 'webagg.open_in_browser', 'backend_fallback', 'toolbar', 'timezone', 'datapath', 'figure.max_open_warning', 'savefig.directory', 'tk.window_focus', 'docstring.hardcopy'} def _remove_blacklisted_style_params(d, warn=True): o = {} for key, val in d.items():
def draw_module_angle_distrib(dat): fileManager = FileManager() angle_statistics_manager = AngleStatisticsManager() module = np.array([row[0] for row in dat]) x = np.array([row[3] for row in dat]) y = np.array([row[4] for row in dat]) z = np.array([row[5] for row in dat]) coord_vectors = [x, y, z] mpl._get_configdir() R = np.math.sqrt((np.sum(x) * np.sum(x)) + (np.sum(y) * np.sum(y)) + (np.sum(z) * np.sum(z))) meanX = np.sum(x) / R meanY = np.sum(y) / R meanZ = np.sum(z) / R meanModule = ArithmeticUtil.arithmetic_mean(module) meanDirection = angle_statistics_manager.mean_direction(coord_vectors) if meanDirection[0] < 0: meanDirection[0] = meanDirection[0] + 180 if meanX < 0: meanDirection[1] = meanDirection[1] + 180 if meanDirection[1] < 0: meanDirection[1] = meanDirection[1] + 360 Ax = meanModule * np.math.sin(ArithmeticUtil.to_radian(meanDirection[0])) * \ np.math.cos(ArithmeticUtil.to_radian(meanDirection[1])) Ay = meanModule * np.math.sin(ArithmeticUtil.to_radian(meanDirection[0])) * \ np.math.sin(ArithmeticUtil.to_radian(meanDirection[1])) Az = meanModule * np.math.cos( ArithmeticUtil.to_radian(meanDirection[0])) w = 80 h = 80 # define 3d plot fig = plt.figure(frameon=False) fig.set_size_inches(w, h) ax = fig.add_subplot(111, projection='3d') max_x = ArithmeticUtil.max_value(abs(x)) max_y = ArithmeticUtil.max_value(abs(y)) max_z = ArithmeticUtil.max_value(abs(z)) max_absolute = max(max_x, max_y, max_z) DrawUtil.draw_sphere(max_absolute * 1.25, 0.08, 0, ax) DrawUtil.draw_axis_vectors(max_absolute * 1.25, 0.05, ax) ax.quiver(0, 0, 0, x, y, z, arrow_length_ratio=0.01, linewidths=0.422) ax.set_xlim(max_absolute * -1, max_absolute) ax.set_ylim(max_absolute * -1, max_absolute) ax.set_zlim(max_absolute * -1, max_absolute) # fig, ax = plt.subplots(num=None, figsize=(16, 12), dpi=80, facecolor='w', edgecolor='k') manager = plt.get_current_fig_manager() manager.window.showMaximized() plt.axis('off') path = fileManager.get_output_path_file() if path != "": if not os.path.exists(path): os.makedirs(path) fig.savefig(path + "/moduleAngleGraph.svg") plt.show()