• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

jjgomera / pychemqt / 97afeac5-3f22-4f23-8496-53a593bdba6c

01 Jun 2026 08:18PM UTC coverage: 73.745% (+0.4%) from 73.367%
97afeac5-3f22-4f23-8496-53a593bdba6c

push

circleci

jjgomera
Fix several fix in latex code of formulae for helical widget

29276 of 39699 relevant lines covered (73.74%)

0.74 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

27.5
/lib/plot.py
1
#!/usr/bin/python3
2
# -*- coding: utf-8 -*-
3

4
'''Pychemqt, Chemical Engineering Process simulator
5
Copyright (C) 2009-2025, Juan José Gómez Romera <jjgomera@gmail.com>
6

7
This program is free software: you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation, either version 3 of the License, or
10
(at your option) any later version.
11

12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
GNU General Public License for more details.
16

17
You should have received a copy of the GNU General Public License
18
along with this program.  If not, see <http://www.gnu.org/licenses/>.'''
19

20

21
###############################################################################
22
# Plot library with all matplotlib functionality
23
###############################################################################
24

25

26
from functools import partial
1✔
27
import os
1✔
28

29
from matplotlib import style
1✔
30
from matplotlib.backends import backend_qtagg
1✔
31
from matplotlib.figure import Figure
1✔
32
from matplotlib.font_manager import FontProperties
1✔
33

34
from lib.config import Preferences
1✔
35
from tools.qt import QtCore, QtGui, QtWidgets, translate
1✔
36
from UI.widgets import (ColorSelector, Entrada_con_unidades, InputFont,
1✔
37
                        LineStyleCombo, MarkerCombo, createAction)
38

39

40
RCParams = {
1✔
41
    # Dict with options, the keys are the keyword matplotlib
42
    # Each option must define:
43
    #   - tooltip for widget with a tiny explanation
44
    #   - Widget class to use
45
    #   - Optional parameters
46
    #       - QComboBox: options to populate widget
47
    #       - QSpinBox: two values for define range (default 0-1)
48
    #       - QDoubleSpinBox: two values for define range (default 0-1),
49
    #           one more to define step (default 0.01 for range 0-1 or 1 in
50
    #           other cases) and one more for define decimals (default 2)
51

52
    "axes.facecolor": (
53
        translate("plot", "Axes background color"), ColorSelector),
54
    "axes.edgecolor": (translate("plot", "Axes edge color"), ColorSelector),
55
    "axes.linewidth": (
56
        translate("plot", "Edge line width"), QtWidgets.QDoubleSpinBox,
57
        0, 5, 0.1, 1),
58
    "axes.grid": (
59
        translate("plot", "Display grid or not"), QtWidgets.QCheckBox),
60
    "axes.grid.axis": (
61
        translate("plot", "Which axis the grid should apply to"),
62
        QtWidgets.QComboBox, "both", "x", "y"),
63
    "axes.grid.which": (
64
        translate("plot", "Grid lines at {major, minor, both} ticks"),
65
        QtWidgets.QComboBox, "both", "major", "minor"),
66
    "axes.titlelocation": (
67
        translate("plot", "Alignment of the title"), QtWidgets.QComboBox,
68
        "left", "right", "center"),
69
    "axes.titlesize": (
70
        translate("plot", "Font size of the axes title"),
71
        QtWidgets.QComboBox, 'xx-small', 'x-small', 'small', 'medium',
72
        'large', 'x-large', 'xx-large'),
73
    "axes.titleweight": (
74
        translate("plot", "Font weight of title"),
75
        QtWidgets.QComboBox, "normal", "bold"),
76
    "axes.titlecolor": (
77
        translate("plot", "Color of axes title"), ColorSelector),
78
    "axes.titley": (
79
        translate("plot", "Position title (axes relative units)"),
80
        QtWidgets.QDoubleSpinBox, 0, 1),
81
    "axes.titlepad": (
82
        translate("plot", "Pad between axes and title in points"),
83
        QtWidgets.QSpinBox, 0, 20),
84
    "axes.labelsize": (
85
        translate("plot", "Font size of the x and y labels"),
86
        QtWidgets.QComboBox, 'xx-small', 'x-small', 'small', 'medium',
87
        'large', 'x-large', 'xx-large'),
88
    "axes.labelpad": (
89
        translate("plot", "Pad between label and axis"),
90
        QtWidgets.QSpinBox, 0, 20),
91
    "axes.labelweight": (
92
        translate("plot", "Weight of the x and y labels"),
93
        QtWidgets.QComboBox, "normal", "bold"),
94
    "axes.labelcolor": (
95
        translate("plot", "Axes label color"), ColorSelector),
96
    "axes.axisbelow": (
97
        translate("plot", "Draw axis gridlines and ticks"),
98
        QtWidgets.QComboBox, "True", "line", "False"),
99
    "axes.formatter.limits": (translate(
100
        "plot", "Use scientific notation if log10 of the axis range "
101
        "is larger than this value"),
102
        QtWidgets.QSpinBox, 0, 10),
103
    "axes.formatter.use_locale": (translate(
104
        "plot", "Format tick labels according to the user's locale"),
105
        QtWidgets.QCheckBox),
106
    "axes.formatter.use_mathtext": (
107
        translate("plot", "Use mathtext for scientific notation"),
108
        QtWidgets.QCheckBox),
109
    "axes.formatter.min_exponent": (
110
        translate("plot", "Minimum exponent to format in scientific notation"),
111
        QtWidgets.QSpinBox, 0, 10),
112
    "axes.formatter.useoffset": (translate(
113
        "plot", "The tick label formatter will default to labeling "
114
        "ticks relative to an offset when the data range is small compared to "
115
        "the minimum absolute value of the data."), QtWidgets.QCheckBox),
116
    "axes.formatter.offset_threshold": (translate(
117
        "plot", "When useoffset is True, the offset will be used when it can "
118
        "remove at least this number of significant digits from tick labels"),
119
        QtWidgets.QSpinBox, 0, 10),
120
    "axes.spines.left": (
121
        translate("plot", "Display axis spines"), QtWidgets.QCheckBox),
122
    "axes.spines.bottom": (
123
        translate("plot", "Display axis spines"), QtWidgets.QCheckBox),
124
    "axes.spines.top": (
125
        translate("plot", "Display axis spines"), QtWidgets.QCheckBox),
126
    "axes.spines.right": (
127
        translate("plot", "Display axis spines"), QtWidgets.QCheckBox),
128
    "axes.unicode_minus": (translate(
129
        "plot", "Use Unicode for the minus symbol rather than hyphen"),
130
        QtWidgets.QCheckBox),
131
    "axes.xmargin": (
132
        translate("plot", "X margin"), QtWidgets.QDoubleSpinBox, 0, 1),
133
    "axes.ymargin": (
134
        translate("plot", "Y margin"), QtWidgets.QDoubleSpinBox, 0, 1),
135
    "axes.zmargin": (
136
        translate("plot", "Z margin"), QtWidgets.QDoubleSpinBox, 0, 1),
137

138
    "axes3d.grid": (
139
        translate("plot", "Display grid on 3D axes"), QtWidgets.QCheckBox),
140

141
    "figure.titlesize": (
142
        translate("plot", "Size of the figure title"),
143
        QtWidgets.QComboBox, 'xx-small', 'x-small', 'small', 'medium',
144
        'large', 'x-large', 'xx-large'),
145
    "figure.titleweight": (
146
        translate("plot", "Weight of the figure title"),
147
        QtWidgets.QComboBox, "normal", "bold"),
148
    "figure.labelsize": (
149
        translate("plot", "Size of the figure label"),
150
        QtWidgets.QComboBox, 'xx-small', 'x-small', 'small', 'medium',
151
        'large', 'x-large', 'xx-large'),
152
    "figure.labelweight": (
153
        translate("plot", "Weight of figure label"),
154
        QtWidgets.QComboBox, "normal", "bold"),
155
    # ("figure.figsize": (,     6.4, 4.8  # figure size in inches
156
    "figure.dpi": (
157
        translate("plot", "Figure dots per inch"),
158
        QtWidgets.QSpinBox, 10, 200),
159
    "figure.facecolor": (
160
        translate("plot", "Figure face color"), ColorSelector),
161
    "figure.edgecolor": (
162
        translate("plot", "Figure edge color"), ColorSelector),
163
    "figure.frameon": (
164
        translate("plot", "Enable figure frame"), QtWidgets.QCheckBox),
165
    "figure.subplot.left": (
166
        translate("plot", "The left side of the subplots of the figure"),
167
        QtWidgets.QDoubleSpinBox, 0, 1),
168
    "figure.subplot.right":
169
        (translate("plot", "The right side of the subplots of the figure"),
170
         QtWidgets.QDoubleSpinBox, 0, 1),
171
    "figure.subplot.bottom": (
172
        translate("plot", "The bottom of the subplots of the figure"),
173
        QtWidgets.QDoubleSpinBox, 0, 1),
174
    "figure.subplot.top": (
175
        translate("plot", "The top of the subplots of the figure"),
176
        QtWidgets.QDoubleSpinBox, 0, 1),
177
    "figure.subplot.wspace": (
178
        translate("plot", "Width reserved for space between subplots"),
179
        QtWidgets.QDoubleSpinBox, 0, 1),
180
    "figure.subplot.hspace": (
181
        translate("plot", "Height reserved for space between subplots"),
182
        QtWidgets.QDoubleSpinBox, 0, 1),
183
    "figure.autolayout": (
184
        translate("plot", "Automatically adjust subplot"),
185
        QtWidgets.QCheckBox),
186
    "figure.constrained_layout.h_pad": (
187
        translate("plot", "Padding around axes objects. Float representing"),
188
        QtWidgets.QDoubleSpinBox, 0, 1),
189
    "figure.constrained_layout.w_pad": (
190
        translate("plot", "Padding around axes objects. Float representing"),
191
        QtWidgets.QDoubleSpinBox, 0, 1),
192
    "figure.constrained_layout.hspace": (
193
        translate("plot", "Space between subplot groups. Float representing"),
194
        QtWidgets.QDoubleSpinBox, 0, 1),
195
    "figure.constrained_layout.wspace": (
196
        translate("plot", "Space between subplot groups. Float representing"),
197
        QtWidgets.QDoubleSpinBox, 0, 1),
198

199
    "font.family": (
200
        "", QtWidgets.QComboBox,
201
        "serif", "sans-serif", "cursive", "fantasy", "monospace"),
202
    "font.style": ("", QtWidgets.QComboBox, "normal", "italic", "oblique"),
203
    "font.variant": ("", QtWidgets.QComboBox, "normal", "small-caps"),
204
    "font.weight": ("", QtWidgets.QComboBox, "normal", "bold"),
205
    "font.stretch": (
206
        "", QtWidgets.QComboBox, "ultra-condensed", "extra-condensed",
207
        "condensed", "semi-condensed", "normal", "semi-expanded", "expanded",
208
        "extra-expanded", "ultra-expanded", "wider", "narrower"),
209
    "font.size": ("", QtWidgets.QDoubleSpinBox, 5, 20, 0.5, 1),
210

211
    "grid.color": (translate("plot", "Grid color"), ColorSelector),
212
    "grid.linestyle": (translate("plot", "Grid line style"), LineStyleCombo),
213
    "grid.linewidth": (
214
        translate("plot", "Grid line width in points"),
215
        QtWidgets.QDoubleSpinBox, 0, 5, 0.1, 1),
216
    "grid.alpha": (
217
        translate("plot", "Grid lines transparency"),
218
        QtWidgets.QDoubleSpinBox, 0, 1),
219

220
    "hatch.linewidth": (
221
        translate("plot", "Line width in points"),
222
        QtWidgets.QDoubleSpinBox, 0, 5, 0.1, 1),
223
    "hatch.color": (translate("plot", "Hatch color"), ColorSelector),
224

225
    "legend.loc": (
226
        translate("plot", "Location of legend in axes"), QtWidgets.QComboBox,
227
        'best', 'center', 'center left', 'center right', 'lower center',
228
        'lower left', 'lower right', 'right', 'upper center', 'upper left',
229
        'upper right'),
230
    "legend.frameon": (
231
        translate("plot", "Draw the legend on a background patch"),
232
        QtWidgets.QCheckBox),
233
    "legend.framealpha": (
234
        translate("plot", "Legend patch transparency"),
235
        QtWidgets.QDoubleSpinBox, 0, 1),
236
    "legend.facecolor": (
237
        translate("plot", "Legend patch color"), ColorSelector),
238
    "legend.edgecolor": (
239
        translate("plot", "Background patch boundary color"), ColorSelector),
240
    "legend.fancybox": (translate(
241
        "plot",
242
        "Use a rounded box for the legend background, else a rectangle"),
243
        QtWidgets.QCheckBox),
244
    "legend.shadow": (
245
        translate("plot", "Give background a shadow effect"),
246
        QtWidgets.QCheckBox),
247
    "legend.numpoints": (
248
        translate("plot", "Number of marker points in the legend line"),
249
        QtWidgets.QSpinBox, 1, 10),
250
    "legend.scatterpoints": (
251
        translate("plot", "Number of scatter points"),
252
        QtWidgets.QSpinBox, 1, 10),
253
    "legend.markerscale": (
254
        translate("plot", "Relative size of legend markers vs. original"),
255
        QtWidgets.QDoubleSpinBox, 0, 2, 0.1, 1),
256
    "legend.fontsize": (
257
        "", QtWidgets.QComboBox, 'xx-small', 'x-small', 'small', 'medium',
258
        'large', 'x-large', 'xx-large'),
259
    "legend.labelcolor": ("", ColorSelector),
260
    "legend.title_fontsize": (
261
        "", QtWidgets.QComboBox, 'xx-small', 'x-small', 'small', 'medium',
262
        'large', 'x-large', 'xx-large'),
263
    "legend.borderpad": (translate(
264
        "plot", "Dimensions as fraction of font size for border whitespace"),
265
        QtWidgets.QDoubleSpinBox, 0, 10, 0.1, 1),
266
    "legend.labelspacing": (translate(
267
        "plot", "Dimensions as fraction of font size for the vertical space "
268
        "between the legend entries"),
269
        QtWidgets.QDoubleSpinBox, 0, 10, 0.1, 1),
270
    "legend.handlelength": (translate(
271
        "plot", "Dimensions as fraction of font size for the length of the "
272
        "legend lines"), QtWidgets.QDoubleSpinBox, 0, 10, 0.1, 1),
273
    "legend.handleheight": (translate(
274
        "plot", "Dimensions as fraction of font size for the height of the "
275
        "legend handle"), QtWidgets.QDoubleSpinBox, 0, 10, 0.1, 1),
276
    "legend.handletextpad": (translate(
277
        "plot", "Dimensions as fraction of font size for the space between "
278
        "the legend line and legend text"),
279
        QtWidgets.QDoubleSpinBox, 0, 10, 0.1, 1),
280
    "legend.borderaxespad": (translate(
281
        "plot", "Dimensions as fraction of font size for the border between "
282
        "the axes and legend edge"), QtWidgets.QDoubleSpinBox, 0, 10, 0.1, 1),
283
    "legend.columnspacing": (translate(
284
        "plot", "Dimensions as fraction of font size for column separation"),
285
        QtWidgets.QDoubleSpinBox, 0, 10, 0.1, 1),
286

287
    "lines.linewidth": (
288
        translate("plot", "Line width in points"),
289
        QtWidgets.QDoubleSpinBox, 0, 10, 0.1, 1),
290
    "lines.linestyle": (translate("plot", "Line style"), LineStyleCombo),
291
    "lines.color": (translate("plot", "Line color"), ColorSelector),
292
    "lines.marker": (translate("plot", "Marker style"), MarkerCombo),
293
    "lines.markerfacecolor": (
294
        translate("plot", "Marker face color"), ColorSelector),
295
    "lines.markeredgecolor": (
296
        translate("plot", "Marker edge color"), ColorSelector),
297
    "lines.markeredgewidth": (
298
        translate("plot", "Line width around the marker symbol"),
299
        QtWidgets.QDoubleSpinBox, 0, 5, 0.1, 1),
300
    "lines.markersize": (
301
        translate("plot", "Marker size, in points"),
302
        QtWidgets.QDoubleSpinBox, 0, 10, 0.1, 1),
303
    "lines.dash_joinstyle": (
304
        "", QtWidgets.QComboBox, "miter", "round", "bevel"),
305
    "lines.dash_capstyle": (
306
        "", QtWidgets.QComboBox, "butt", "round", "projecting"),
307
    "lines.solid_joinstyle": (
308
        "", QtWidgets.QComboBox, "miter", "round", "bevel"),
309
    "lines.solid_capstyle": (
310
        "", QtWidgets.QComboBox, "butt", "round", "projecting"),
311
    "lines.antialiased": (
312
        translate("plot", "Render antialiased"), QtWidgets.QCheckBox),
313
    "lines.scale_dashes": ("", QtWidgets.QCheckBox),
314

315
    "patch.linewidth": (
316
        translate("plot", "Edge width in points"),
317
        QtWidgets.QDoubleSpinBox, 0, 10, 0.1, 1),
318
    "patch.facecolor": (translate("plot", "Patch face color"), ColorSelector),
319
    "patch.edgecolor": (translate("plot", "Patch edge color"), ColorSelector),
320
    "patch.force_edgecolor": (
321
        translate("plot", "Always use edgecolor"), QtWidgets.QCheckBox),
322
    "patch.antialiased": (
323
        translate("plot", "Render patch antialiased"), QtWidgets.QCheckBox),
324

325
    "xtick.top": (
326
        translate("plot", "Draw ticks on the top side"), QtWidgets.QCheckBox),
327
    "xtick.bottom": (
328
        translate("plot", "Draw ticks on the bottom side"),
329
        QtWidgets.QCheckBox),
330
    "xtick.labeltop": (
331
        translate("plot", "Draw label on the top"), QtWidgets.QCheckBox),
332
    "xtick.labelbottom": (
333
        translate("plot", "Draw label on the bottom"), QtWidgets.QCheckBox),
334
    "xtick.major.size": (
335
        translate("plot", "Major tick size in points"),
336
        QtWidgets.QDoubleSpinBox, 0, 10, 0.1, 1),
337
    "xtick.minor.size": (
338
        translate("plot", "Minor tick size in points"),
339
        QtWidgets.QDoubleSpinBox, 0, 10, 0.1, 1),
340
    "xtick.major.width": (
341
        translate("plot", "Major tick width in points"),
342
        QtWidgets.QDoubleSpinBox, 0, 10, 0.1, 1),
343
    "xtick.minor.width": (
344
        translate("plot", "Minor tick width in points"),
345
        QtWidgets.QDoubleSpinBox, 0, 10, 0.1, 1),
346
    "xtick.major.pad": (
347
        translate("plot", "Distance to major tick label in points"),
348
        QtWidgets.QDoubleSpinBox, 0, 20, 0.1, 1),
349
    "xtick.minor.pad": (
350
        translate("plot", "Distance to the minor tick label in points"),
351
        QtWidgets.QDoubleSpinBox, 0, 20, 0.1, 1),
352
    "xtick.color": (translate("plot", "Color of the ticks"), ColorSelector),
353
    "xtick.labelcolor": (translate(
354
        "plot", "Color of the tick labels or inherit from xtick.color"),
355
        ColorSelector),
356
    "xtick.labelsize": (
357
        translate("plot", "Font size of the tick labels"),
358
        QtWidgets.QComboBox, 'xx-small', 'x-small', 'small', 'medium', 'large',
359
        'x-large', 'xx-large'),
360
    "xtick.direction": (
361
        translate("plot", "Direction"), QtWidgets.QComboBox,
362
        "in", "out", "inout"),
363
    "xtick.minor.visible": (
364
        translate("plot", "Visibility of minor ticks on x-axis"),
365
        QtWidgets.QCheckBox),
366
    "xtick.major.top": (
367
        translate("plot", "Draw x axis top major ticks"), QtWidgets.QCheckBox),
368
    "xtick.major.bottom": (
369
        translate("plot", "Draw x axis bottom major ticks"),
370
        QtWidgets.QCheckBox),
371
    "xtick.minor.top": (
372
        translate("plot", "Draw x axis top minor ticks"), QtWidgets.QCheckBox),
373
    "xtick.minor.bottom": (
374
        translate("plot", "Draw x axis bottom minor ticks"),
375
        QtWidgets.QCheckBox),
376
    "xtick.alignment": (
377
        translate("plot", "Alignment of ticks"), QtWidgets.QComboBox,
378
        "left", "center", "right"),
379

380
    "ytick.left": (
381
        translate("plot", "Draw ticks on the left side"), QtWidgets.QCheckBox),
382
    "ytick.right": (
383
        translate("plot", "Draw ticks on the right side"),
384
        QtWidgets.QCheckBox),
385
    "ytick.labelleft": (
386
        translate("plot", "Draw label on the left"), QtWidgets.QCheckBox),
387
    "ytick.labelright": (
388
        translate("plot", "Draw label on the right"), QtWidgets.QCheckBox),
389
    "ytick.major.size": (
390
        translate("plot", "Major tick size in points"),
391
        QtWidgets.QDoubleSpinBox, 0, 10, 0.1, 1),
392
    "ytick.minor.size": (
393
        translate("plot", "Minor tick size in points"),
394
        QtWidgets.QDoubleSpinBox, 0, 10, 0.1, 1),
395
    "ytick.major.width": (
396
        translate("plot", "Major tick width in points"),
397
        QtWidgets.QDoubleSpinBox, 0, 10, 0.1, 1),
398
    "ytick.minor.width": (
399
        translate("plot", "Minor tick width in points"),
400
        QtWidgets.QDoubleSpinBox, 0, 10, 0.1, 1),
401
    "ytick.major.pad": (
402
        translate("plot", "Distance to major tick label in points"),
403
        QtWidgets.QDoubleSpinBox, 0, 20, 0.1, 1),
404
    "ytick.minor.pad": (
405
        translate("plot", "Distance to the minor tick label in points"),
406
        QtWidgets.QDoubleSpinBox, 0, 20, 0.1, 1),
407
    "ytick.color": (translate("plot", "Color of the ticks"), ColorSelector),
408
    "ytick.labelcolor": (translate(
409
        "plot", "Color of the tick labels or inherit from ytick.color"),
410
        ColorSelector),
411
    "ytick.labelsize": (
412
        translate("plot", "Font size of the tick labels"),
413
        QtWidgets.QComboBox, 'xx-small', 'x-small', 'small', 'medium', 'large',
414
        'x-large', 'xx-large'),
415
    "ytick.direction": (
416
        translate("plot", "Direction"), QtWidgets.QComboBox,
417
        "in", "out", "inout"),
418
    "ytick.minor.visible": (
419
        translate("plot", "Visibility of minor ticks on y-axis"),
420
        QtWidgets.QCheckBox),
421
    "ytick.major.left": (
422
        translate("plot", "Draw y axis left major ticks"),
423
        QtWidgets.QCheckBox),
424
    "ytick.major.right": (
425
        translate("plot", "Draw y axis right major ticks"),
426
        QtWidgets.QCheckBox),
427
    "ytick.minor.left": (
428
        translate("plot", "Draw y axis left minor ticks"),
429
        QtWidgets.QCheckBox),
430
    "ytick.minor.right": (
431
        translate("plot", "Draw y axis right minor ticks"),
432
        QtWidgets.QCheckBox),
433
    "ytick.alignment": (
434
        translate("plot", "Alignment of ticks"), QtWidgets.QComboBox,
435
        'bottom', 'baseline', 'center', 'center_baseline', 'top'),
436

437
    "xaxis.labellocation": (
438
        translate("plot", "Alignment of the xaxis label"),
439
        QtWidgets.QComboBox, "center", "left", "right"),
440
    "yaxis.labellocation": (
441
        translate("plot", "Alignment of the yaxis label"),
442
        QtWidgets.QComboBox, "center", "bottom", "top"),
443

444
    "savefig.dpi": (
445
        translate("plot", "Figure dots per inch"), QtWidgets.QSpinBox, 0, 100),
446
    "savefig.facecolor": (
447
        translate("plot", "Figure facecolor when saving"), ColorSelector),
448
    "savefig.edgecolor": (
449
        translate("plot", "Figure edgecolor when saving"), ColorSelector),
450
    "savefig.format": (
451
        translate("plot", "File format so save"), QtWidgets.QComboBox,
452
        "png", "ps", "pdf", "svg"),
453
    "savefig.bbox": ("", QtWidgets.QComboBox, "standard", "tight"),
454
    "savefig.pad_inches": (translate(
455
        "plot", "Padding to be used, when bbox is set to 'tight'"),
456
        QtWidgets.QDoubleSpinBox, 0, 10, 0.1, 1),
457
    "savefig.transparent": (
458
        translate("plot", "Figures are saved with a transparent background"),
459
        QtWidgets.QCheckBox)}
460

461

462
class PlotWidget(backend_qtagg.FigureCanvasQTAgg):
1✔
463
    """QWidget with matplotlib integration"""
464
    def __init__(self, dim=2, width=15, height=5, dpi=100, parent=None):
1✔
465
        self.fig = Figure(figsize=(width, height), dpi=dpi)
×
466
        super().__init__(self.fig)
×
467

468
        self.dim = dim
×
469
        self.setParent(parent)
×
470
        self.setSizePolicy(
×
471
            QtWidgets.QSizePolicy.Policy.Expanding,
472
            QtWidgets.QSizePolicy.Policy.Expanding)
473

474
        if dim == 2:
×
475
            self.ax = self.fig.add_subplot(111)
×
476

477
        elif dim == 3:
×
478
            self.ax = self.fig.add_subplot(projection="3d")
×
479
            self.ax.mouse_init(rotate_btn=1, zoom_btn=2)
×
480
        # In any other case the axes are not defined and can be configured at
481
        # used site
482

483
    def plot(self, *args, **kwargs):
1✔
484
        """Direct accesst to ax plot procedure"""
485
        self.ax.plot(*args, **kwargs)
×
486

487
    def savePNG(self):
1✔
488
        """Save chart image to png file"""
489
        fmt = "Portable Network Graphics (*.png)"
×
490
        fname, ext = QtWidgets.QFileDialog.getSaveFileName(
×
491
            self, translate("Save chart to file"), "./", fmt)
492
        if fname and ext == fmt:
×
493
            if fname.split(".")[-1] != "png":
×
494
                fname += ".png"
×
495
            self.fig.savefig(fname, facecolor='#fafafa')
×
496

497
    # def plot_3D(self, labels, xdata, ydata, zdata, config=None):
498
        # """Método que dibuja la matriz de datos"""
499
        # self.ax.clear()
500
        # self.data = {"x": xdata[0], "y": ydata[:, 0], "z": zdata}
501

502
        # if config and config.getboolean("MEOS", "surface"):
503
            # self.ax.plot_surface(xdata, ydata, zdata, rstride=1, cstride=1)
504
        # else:
505
            # self.ax.plot_wireframe(xdata, ydata, zdata, rstride=1, cstride=1)
506

507
        # self.ax.set_xlabel(labels[0])
508
        # self.ax.set_ylabel(labels[1])
509
        # self.ax.set_zlabel(labels[2])
510
        # self.ax.mouse_init(rotate_btn=1, zoom_btn=2)
511

512

513
class PlotDialog(QtWidgets.QDialog):
1✔
514
    """QDialog including Plotwidget, navigationtoolbar and a button to close"""
515
    def __init__(self, accept=False, cancel=True, parent=None):
1✔
516
        super().__init__(parent)
×
517
        gridLayout = QtWidgets.QGridLayout(self)
×
518

519
        self.plot = PlotWidget()
×
520
        gridLayout.addWidget(self.plot, 1, 1, 1, 2)
×
521
        self.toolbar = backend_qtagg.NavigationToolbar2QT(self.plot, self.plot)
×
522
        gridLayout.addWidget(self.toolbar, 2, 1)
×
523
        btonBox = QtWidgets.QDialogButtonBox()
×
524
        if accept:
×
525
            btonBox.addButton(QtWidgets.QDialogButtonBox.StandardButton.Ok)
×
526
            btonBox.accepted.connect(self.accept)
×
527
        if cancel:
×
528
            btonBox.addButton(QtWidgets.QDialogButtonBox.StandardButton.Cancel)
×
529
            btonBox.rejected.connect(self.reject)
×
530
        btonBox.setSizePolicy(QtWidgets.QSizePolicy.Policy.Maximum,
×
531
                              QtWidgets.QSizePolicy.Policy.Maximum)
532
        gridLayout.addWidget(btonBox, 2, 2)
×
533

534
    def addText(self, *args, **kwargs):
1✔
535
        """Direct access to ax text procedure"""
536
        self.plot.ax.text(*args, **kwargs)
×
537

538
    def addData(self, *args, **kwargs):
1✔
539
        """Direct access to ax plot procedure"""
540
        self.plot.ax.plot(*args, **kwargs)
×
541

542

543
# Load style defined in preferences
544
if Preferences.getboolean("Plot", 'customize'):
1✔
545
    rc = {}
×
546
    for key, (tip, widget, *args) in RCParams.items():
×
547
        if widget == QtWidgets.QDoubleSpinBox:
×
548
            rc[key] = Preferences.getfloat("Plot", key)
×
549
        elif widget == QtWidgets.QSpinBox:
×
550
            if key == "axes.formatter.limits":
×
551
                rc[key] = Preferences.get("Plot", key)
×
552
            else:
553
                rc[key] = Preferences.getint("Plot", key)
×
554
        elif widget == QtWidgets.QCheckBox:
×
555
            rc[key] = Preferences.getboolean("Plot", key)
×
556
        else:
557
            rc[key] = Preferences.get("Plot", key)
×
558
    style.use(rc)
×
559
elif Preferences.getint("Plot", 'style') == 0:
1✔
560
    style.use("default")
1✔
561
else:
562
    style.use(style.available[Preferences.getint("Plot", 'style')-1])
×
563

564

565
if __name__ == "__main__":
1✔
566
    import os
×
567
    import sys
×
568
    from configparser import ConfigParser
×
569
    conf_dir = os.path.expanduser('~') + "/.pychemqt/"
×
570
    pychemqt_dir = os.environ["PWD"] + "/"
×
571
    app = QtWidgets.QApplication(sys.argv)
×
572

573
    conf = ConfigParser()
×
574
    conf.read(conf_dir+"pychemqtrc")
×
575
    dialogo = ConfPlot(conf)
×
576

577
    dialogo.show()
×
578
    sys.exit(app.exec())
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc