Path: blob/main/tools/contributed/sumopy/agilepy/lib_misc/matplotlibtools.py
169689 views
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo1# Copyright (C) 2016-2025 German Aerospace Center (DLR) and others.2# SUMOPy module3# Copyright (C) 2012-2021 University of Bologna - DICAM4# This program and the accompanying materials are made available under the5# terms of the Eclipse Public License 2.0 which is available at6# https://www.eclipse.org/legal/epl-2.0/7# This Source Code may also be made available under the following Secondary8# Licenses when the conditions for such availability set forth in the Eclipse9# Public License 2.0 are satisfied: GNU General Public License, version 210# or later which is available at11# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html12# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later1314# @file matplotlibtools.py15# @author Joerg Schweizer16# @date 20121718from os import system19import matplotlib20import matplotlib.pyplot as plt21from mpl_toolkits.mplot3d import Axes3D22from matplotlib.collections import PolyCollection232425from mpl_toolkits.axes_grid import make_axes_locatable2627##############################################################################28# matplotlib configuration2930linewidth = 2.031fontsize = 12323334params = { # 'backend': 'ps',35'axes.labelsize': fontsize,36'text.fontsize': fontsize,37'legend.fontsize': 0.9*fontsize,38'xtick.labelsize': 0.9*fontsize,39'ytick.labelsize': 0.9*fontsize,40'text.usetex': False,41# 'figure.figsize': fig_size42}4344matplotlib.rcParams.update(params)4546markers = ['o', 's', '^', 'd', 'v', '*', 'h', '<', '>']47markersize = 848nodesize = 100049##############################################################################505152def init_plot(is_tight_layout=False, ind_fig=0, **kwargs):53plt.close("all")54fig = plt.figure(ind_fig, **kwargs)55ax = fig.add_subplot(111)56if is_tight_layout:57fig.tight_layout()58return ax596061def new_plot(is_tight_layout=False, ind_fig=0):6263fig = plt.figure(ind_fig)64ax = fig.add_subplot(111)65if is_tight_layout:66fig.tight_layout()67ind_fig += 168return ax, ind_fig697071def save_fig(figname, is_adjust_border=False):72#ffigname = figname+".png"73# plt.savefig(ffigname,format='PNG')7475ffigname = figname+".pdf"76if is_adjust_border:77plt.subplots_adjust(left=0.12, bottom=0.1, right=0.86, top=0.9, wspace=0.2, hspace=0.2)7879plt.savefig(figname+".pdf", format='PDF')80# plt.savefig(figname+".eps",format='eps',transparent=True)81#system("ps2pdf -dEPSCrop "+figname+".eps "+figname+".pdf")82#system("rm "+figname+".eps")83return ffigname848586