Welcome to Knowage Q&A, where you can ask questions and receive answers from other members of the community.
0 votes
1 view

Hello I would like to have multiple plots in one function using a python script.

I have tried two possibilies:

1)

import matplotlib.pyplot as plt1

import matplotlib.pyplot as plt2

and than draw in both plt1 and plt2 unfortunately they draw in each other....

2)

using figures

import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import numpy as np


fig1 = plt.figure()
fig2 = plt.figure()

x = np.linspace(0,10,1000)
y1 = x**2
y2 = np.sin(x)

ax1 = fig1.add_subplot(1, 1, 1)
ax2 = fig2.add_subplot(1, 1, 1)
ax1.plot(x,y1)
ax2.plot(x,y2)

but this yields the following error:

Traceback (most recent call last):
  File "<string>", line 2, in <module>
AttributeError: 'Figure' object has no attribute 'gcf'
it.eng.spagobi.utilities.exceptions.SpagoBIRuntimeException: Python engine error
Technical details:
PythonOutputExecutor.java:
fig1.savefig('fig1.png')
fig1.gcf().clear()
fig1.gcf().clear()
EXECUTION FAILED
See log file for other details

Grateful for any help

Environment Knowage 6.11 Debian9
in Data Mining by (710 points)

1 Answer

0 votes

In the second case, you got error because you bind output image to figures, and Knowage treats them as pyplot:

https://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.gcf

The first approach is fine, and if you have a reproducible issue please file a bug on https://www.knowage-suite.com/jira

by (15.2k points)
...