Commit 17f9a1f2 authored by Nikita Sirgienko's avatar Nikita Sirgienko

[T9475] Python Plot Extension: Add support for different packages

parent 89f11e9c
Pipeline #25214 passed with stage
in 18 minutes and 12 seconds
......@@ -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>
......@@ -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("\nmlab.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)
......
......@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>660</width>
<height>300</height>
<height>331</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 &quot;Plot&quot; Cantor menu.</string>
</property>
<property name="text">
<string>Prefered package for &quot;Plot&quot; 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>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment