I was just wondering if there is a way to also create a loop of embedded plot figures. Right now I am using a for loop to create multiple separate plot windows. So I was hoping I could use a similar for loop to create the figures and embed them in a GUI i am making. Also if anyone is familiar with Pyforms, is there a way to use a loop to make multiple controlwidgets of the same type?
EDIT:
Sorry. Let me clarify the question. I created a program that grabs data from the EIA API and then produces graphs with that data. So far I successfully used a for loop that produces a graph for each series of interest. The loop is the following:
for idx, plot in enumerate(plots):
figs[idx] = plt.figure()
axs[idx] = figs[idx].add_subplot(111)
axs[idx].plot(plot[0], plot[1])
series_xlabel = []
i = 0
while i < series_count:
series_xlabel.append(plot[0][i])
i += round(series_count / 23)
axs[idx].set_xticklabels(reversed(series_xlabel))
axs[idx].locator_params('x', nbins=23)
axs[idx].tick_params('x', rotation=22)
axs[idx].set_xlabel('Dates')
axs[idx].set_ylabel(series_rawdata_yname[idx])
axs[idx].set_title(series_rawdata_sname[idx])
Where plots
is a list and each item within it is the rawdata of each series pulled from the API. The loop also pulls and names each graph with the corresponding title for each series pulled. Each graph is made in a seperate figure window, which is fine for now, but I would like to embed each of these figures into a GUI I am making using the Pyforms library. Now Pyforms has compatibility with matplotlib and even has its own widget for matplotlib figures, but I can't figure out how to use the widget in a loop. As such I was thinking an alternative would be to use the aforementioned loop to embed each of the figures into the GUI. I was wondering if this is possible.
With regards to Pyforms, I have tried testing whether or not you can use loops with the widgets it provides. It seems to be able to use a loop, but it only shows the last iteration of the loop in the test GUI. The test code i made is the following:
import pyforms
from pyforms import BaseWidget
from pyforms.Controls import ControlDockWidget
from pyforms.Controls import ControlMatplotlib
class test(BaseWidget):
def __init__(self):
super(test, self).__init__('test')
self.itr = [1, 2, 3, 4, 5]
for item in self.itr:
self._graph = ControlMatplotlib(item)
self.formset = [{
'tab%s' %item:['_graph']
}]
if __name__ == "__main__":
pyforms.start_app(test)
The end result is that it only shows tab5
and its corresponding graph in the window. Is there a way to fix it so it shows each tab and graphwidget produced in the for loop?
Update: so I figured out how to make a loop to produce multiple tabs. The problem I am having now is that it only shows the Matplotlib control widget in the last tab. I assume it is something wrong with the loop still. Here is what the code looks like now:
import pyforms
from pyforms import BaseWidget
from pyforms.Controls import ControlButton
from pyforms.Controls import ControlMatplotlib
class test(BaseWidget):
def __init__(self):
super(test, self).__init__('test')
self.formset = [{}]
for i in range(0, 5):
self._graph = ControlMatplotlib('%s' %i)
self.formset[0]['tab%s' %i] = ['_graph']
if __name__ == "__main__":
pyforms.start_app(test)
If you have the Pyforms Library and run this code it will produce five tabs, but only on the last tab will a Matplotlib widget show. I would like to figure out a way to fix the loop so all the tabs will have the Matplotlib Widget showing.