Dear Patrik,
Thank you so much for your code! It was really refreshing!
Meanwhile I sort out how to modify the "Matplotlib.py" exporter from
pyqtgraph so
one can plot the errors on the "matplot gui window: for further plot
customization.
Very minimal example (that so far works for me) is:
in "Matplotlib.py" add the following loop inside the export() function:
def export(self, fileName=None):
if isinstance(self.item, PlotItem):
mpw = MatplotlibWindow()
MatplotlibExporter.windows.append(mpw)
stdFont = 'Arial'
fig = mpw.getFigure()
# get labels from the graphic item
xlabel = self.item.axes['bottom']['item'].label.toPlainText()
ylabel = self.item.axes['left']['item'].label.toPlainText()
title = self.item.titleLabel.text
ax = fig.add_subplot(111, title=title)
ax.clear()
self.cleanAxes(ax)
#ax.grid(True)
for indx, item in enumerate(self.item.curves):
x, y = item.getData()
if x is None:
continue
opts = item.opts
#print(opts)
pen = fn.mkPen(opts['pen'])
if pen.style() == QtCore.Qt.NoPen:
linestyle = ''
else:
linestyle = '-'
color = tuple([c/255. for c in fn.colorTuple(pen.color())])
symbol = opts['symbol']
if symbol == 't':
symbol = '^'
symbolPen = fn.mkPen(opts['symbolPen'])
symbolBrush = fn.mkBrush(opts['symbolBrush'])
markeredgecolor = tuple([c/255. for c in fn.colorTuple(
symbolPen.color())])
markerfacecolor = tuple([c/255. for c in fn.colorTuple(
symbolBrush.color())])
markersize = opts['symbolSize']
if opts['fillLevel'] is not None and opts['fillBrush'] is
not None:
fillBrush = fn.mkBrush(opts['fillBrush'])
fillcolor = tuple([c/255. for c in fn.colorTuple(
fillBrush.color())])
ax.fill_between(x=x, y1=y, y2=opts['fillLevel'],
facecolor=fillcolor)
ax.plot(x, y, marker=symbol, color=color, linewidth=pen.
width(),
linestyle=linestyle,
markeredgecolor=markeredgecolor,
markerfacecolor=markerfacecolor,
markersize=markersize)
xr, yr = self.item.viewRange()
ax.set_xbound(*xr)
ax.set_ybound(*yr)
###### This is the simple hack: the loops looks for
ErrorBarItem is inside "items" and plots them using the mpl errorbar()
for indx, item in enumerate(self.item.items):
if indx <=1:
continue
if "height" in self.item.items[indx].opts:
ax.errorbar(x=self.item.items[indx].opts["x"], y=
self.item.items[indx].opts["y"],
yerr=self.item.items[indx].opts[
"height"]/2., linestyle='', marker='o',markersize=0.5, linewidth=1.0,
color=self.item.items[indx].opts["pen"
], capsize = 0, elinewidth=1,mew=0.0, zorder=-10)
################### end of the hack
################################
ax.set_xlabel(xlabel) # place the labels.
ax.set_ylabel(ylabel)
ax.spines['top'].set_color('k')
ax.spines['right'].set_color('k')
mpw.draw()
else:
raise Exception("Matplotlib export currently only works with
plot items")
Fairly easy but one must be more familiar with the pyqtgraph architecture,
while I am still learning,,,,,
However, there are still problems.
For example the "edit axis, curves and image parameters" option in the
matplotlib gui window can modify only the
curves created with ax.plot() but not the errorbars introduced with
ax.errorbar(). Thus, if one wants to change the color
can do it only for the data point but not for the erorrbar, which is
annoying.
Also, some control on the axis labels and "dpi" would have been nice to
have.
Hopefully the new pyqtgraph will warp the matplotlib more flexibly!
Thanks a lot again!
Trifon
--
You received this message because you are subscribed to the Google Groups
"pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/pyqtgraph/291c81d9-7aa8-41f2-bd76-9da53084635a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.