Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Education
Cantor
Commits
17f9a1f2
Commit
17f9a1f2
authored
Jun 28, 2020
by
Nikita Sirgienko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[T9475] Python Plot Extension: Add support for different packages
parent
89f11e9c
Pipeline
#25214
passed with stage
in 18 minutes and 12 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
129 additions
and
14 deletions
+129
-14
src/backends/python/pythonbackend.kcfg
src/backends/python/pythonbackend.kcfg
+11
-0
src/backends/python/pythonextensions.cpp
src/backends/python/pythonextensions.cpp
+68
-13
src/backends/python/settings.ui
src/backends/python/settings.ui
+50
-1
No files found.
src/backends/python/pythonbackend.kcfg
View file @
17f9a1f2
...
...
@@ -33,5 +33,16 @@
<label>
Graphical package, for which will be enable support for embedding plots
</label>
<default>
0
</default>
</entry>
<entry
name=
"plotExtenstionGraphicPackage"
type=
"Enum"
>
<choices>
<choice
name=
"matplotlib"
/>
<choice
name=
"pylab"
/>
<choice
name=
"plotly"
/>
<choice
name=
"gr"
/>
<choice
name=
"bokeh"
/>
</choices>
<label>
Graphical package, for which will be enable support for embedding plots
</label>
<default>
0
</default>
</entry>
</group>
</kcfg>
src/backends/python/pythonextensions.cpp
View file @
17f9a1f2
...
...
@@ -26,6 +26,8 @@
#include "pythonutils.h"
#include "settings.h"
#define PYTHON_EXT_CDTOR(name) Python##name##Extension::Python##name##Extension(QObject* parent) : name##Extension(parent) {} \
Python##name##Extension::~Python##name##Extension() {}
...
...
@@ -131,21 +133,74 @@ PYTHON_EXT_CDTOR(Plot)
QString
PythonPlotExtension
::
plotFunction2d
(
const
QString
&
function
,
const
QString
&
variable
,
const
QString
&
left
,
const
QString
&
right
)
{
QString
argumentToPlot
=
variable
;
QString
xlimits
;
if
(
!
function
.
isEmpty
()){
argumentToPlot
=
function
+
QLatin1String
(
"("
)
+
variable
+
QLatin1String
(
")"
);
}
QString
command
;
QString
limits
;
if
(
!
left
.
isEmpty
()
&&
!
right
.
isEmpty
()){
xlimits
=
QString
::
fromLatin1
(
"pylab.xlim(%1, %2)
\n
"
).
arg
(
left
,
right
);
}
int
val
=
PythonSettings
::
plotExtenstionGraphicPackage
();
switch
(
val
)
{
case
PythonSettings
::
EnumPlotExtenstionGraphicPackage
::
matplotlib
:
if
(
!
left
.
isEmpty
()
&&
!
right
.
isEmpty
())
limits
=
QString
::
fromLatin1
(
"plt.xlim(%1, %2)
\n
"
).
arg
(
left
,
right
);
command
=
QString
::
fromLatin1
(
"import matplotlib.pyplot as plt
\n
"
"
\n
"
"plt.plot(%1, %2)
\n
"
"%3"
"plt.show()"
).
arg
(
variable
,
function
,
limits
);
break
;
case
PythonSettings
::
EnumPlotExtenstionGraphicPackage
::
pylab
:
if
(
!
left
.
isEmpty
()
&&
!
right
.
isEmpty
())
limits
=
QString
::
fromLatin1
(
"pylab.xlim(%1, %2)
\n
"
).
arg
(
left
,
right
);
command
=
QString
::
fromLatin1
(
"import pylab
\n
"
"
\n
"
"pylab.clf()
\n
"
"pylab.plot(%1, %2)
\n
"
"%3"
"pylab.show()"
).
arg
(
variable
,
function
,
limits
);
break
;
case
PythonSettings
::
EnumPlotExtenstionGraphicPackage
::
plotly
:
if
(
!
left
.
isEmpty
()
&&
!
right
.
isEmpty
())
limits
=
QString
::
fromLatin1
(
"fig.update_layout(xaxis=dict(range=[%1, %2]))
\n
"
).
arg
(
left
,
right
);
command
=
QString
::
fromLatin1
(
"import plotly.graph_objects as go
\n
"
"
\n
"
"fig = go.Figure(data=go.Scatter(x=%1, y=%2))
\n
"
"%3"
"fig.show()"
).
arg
(
variable
,
function
,
limits
);
break
;
case
PythonSettings
::
EnumPlotExtenstionGraphicPackage
::
gr
:
if
(
!
left
.
isEmpty
()
&&
!
right
.
isEmpty
())
limits
=
QString
::
fromLatin1
(
"
\n
mlab.xlim(%1, %2)"
).
arg
(
left
,
right
);
command
=
QString
::
fromLatin1
(
"from gr.pygr import mlab
\n
"
"
\n
"
"mlab.plot(%1, %2)"
"%3"
).
arg
(
variable
,
function
,
limits
);
break
;
case
PythonSettings
::
EnumPlotExtenstionGraphicPackage
::
bokeh
:
if
(
!
left
.
isEmpty
()
&&
!
right
.
isEmpty
())
limits
=
QString
::
fromLatin1
(
"x_range=(%1, %2)"
).
arg
(
left
,
right
);
command
=
QString
::
fromLatin1
(
"from bokeh.plotting import figure, show
\n
"
"
\n
"
"fig = figure(%3)
\n
"
"fig.line(%1, %2)
\n
"
"show(fig)"
).
arg
(
variable
,
function
,
limits
);
break
;
};
return
QString
::
fromLatin1
(
"pylab.clf()
\n
"
\
"pylab.plot(%1)
\n
"
\
"%2"
\
"pylab.show()"
).
arg
(
argumentToPlot
,
xlimits
);
return
command
;
}
QString
PythonPlotExtension
::
plotFunction3d
(
const
QString
&
function
,
const
VariableParameter
&
var1
,
const
VariableParameter
&
var2
)
...
...
src/backends/python/settings.ui
View file @
17f9a1f2
...
...
@@ -7,7 +7,7 @@
<x>
0
</x>
<y>
0
</y>
<width>
660
</width>
<height>
3
00
</height>
<height>
3
31
</height>
</rect>
</property>
<layout
class=
"QVBoxLayout"
name=
"verticalLayout"
>
...
...
@@ -66,6 +66,55 @@
</property>
</widget>
</item>
<item>
<layout
class=
"QHBoxLayout"
name=
"horizontalLayout4"
>
<item>
<widget
class=
"QLabel"
name=
"label4"
>
<property
name=
"toolTip"
>
<string>
Graphic package, which code will used for plotting via
"
Plot
"
Cantor menu.
</string>
</property>
<property
name=
"text"
>
<string>
Prefered package for
"
Plot
"
menu:
</string>
</property>
</widget>
</item>
<item>
<widget
class=
"KComboBox"
name=
"kcfg_plotExtenstionGraphicPackage"
>
<property
name=
"sizePolicy"
>
<sizepolicy
hsizetype=
"Expanding"
vsizetype=
"Fixed"
>
<horstretch>
0
</horstretch>
<verstretch>
0
</verstretch>
</sizepolicy>
</property>
<item>
<property
name=
"text"
>
<string>
matplotlib
</string>
</property>
</item>
<item>
<property
name=
"text"
>
<string>
pylab
</string>
</property>
</item>
<item>
<property
name=
"text"
>
<string>
plot.ly
</string>
</property>
</item>
<item>
<property
name=
"text"
>
<string>
GR
</string>
</property>
</item>
<item>
<property
name=
"text"
>
<string>
bokeh
</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<layout
class=
"QHBoxLayout"
name=
"horizontalLayout3"
>
<item>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment