Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tools/contributed/sumopy/agilepy/lib_misc/matplotlibtools.py
169689 views
1
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
2
# Copyright (C) 2016-2025 German Aerospace Center (DLR) and others.
3
# SUMOPy module
4
# Copyright (C) 2012-2021 University of Bologna - DICAM
5
# This program and the accompanying materials are made available under the
6
# terms of the Eclipse Public License 2.0 which is available at
7
# https://www.eclipse.org/legal/epl-2.0/
8
# This Source Code may also be made available under the following Secondary
9
# Licenses when the conditions for such availability set forth in the Eclipse
10
# Public License 2.0 are satisfied: GNU General Public License, version 2
11
# or later which is available at
12
# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
13
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
14
15
# @file matplotlibtools.py
16
# @author Joerg Schweizer
17
# @date 2012
18
19
from os import system
20
import matplotlib
21
import matplotlib.pyplot as plt
22
from mpl_toolkits.mplot3d import Axes3D
23
from matplotlib.collections import PolyCollection
24
25
26
from mpl_toolkits.axes_grid import make_axes_locatable
27
28
##############################################################################
29
# matplotlib configuration
30
31
linewidth = 2.0
32
fontsize = 12
33
34
35
params = { # 'backend': 'ps',
36
'axes.labelsize': fontsize,
37
'text.fontsize': fontsize,
38
'legend.fontsize': 0.9*fontsize,
39
'xtick.labelsize': 0.9*fontsize,
40
'ytick.labelsize': 0.9*fontsize,
41
'text.usetex': False,
42
# 'figure.figsize': fig_size
43
}
44
45
matplotlib.rcParams.update(params)
46
47
markers = ['o', 's', '^', 'd', 'v', '*', 'h', '<', '>']
48
markersize = 8
49
nodesize = 1000
50
##############################################################################
51
52
53
def init_plot(is_tight_layout=False, ind_fig=0, **kwargs):
54
plt.close("all")
55
fig = plt.figure(ind_fig, **kwargs)
56
ax = fig.add_subplot(111)
57
if is_tight_layout:
58
fig.tight_layout()
59
return ax
60
61
62
def new_plot(is_tight_layout=False, ind_fig=0):
63
64
fig = plt.figure(ind_fig)
65
ax = fig.add_subplot(111)
66
if is_tight_layout:
67
fig.tight_layout()
68
ind_fig += 1
69
return ax, ind_fig
70
71
72
def save_fig(figname, is_adjust_border=False):
73
#ffigname = figname+".png"
74
# plt.savefig(ffigname,format='PNG')
75
76
ffigname = figname+".pdf"
77
if is_adjust_border:
78
plt.subplots_adjust(left=0.12, bottom=0.1, right=0.86, top=0.9, wspace=0.2, hspace=0.2)
79
80
plt.savefig(figname+".pdf", format='PDF')
81
# plt.savefig(figname+".eps",format='eps',transparent=True)
82
#system("ps2pdf -dEPSCrop "+figname+".eps "+figname+".pdf")
83
#system("rm "+figname+".eps")
84
return ffigname
85
86