2017-08-05 49 views
0

我有这样的代码来生成一个数字:pyqtgraph出口SVG凌乱/移

代码:

import pyqtgraph as pg 
from pyqtgraph.Qt import QtCore, QtGui 
import numpy as np 
import pandas as pd 
import pyqtgraph.exporters 


pg.setConfigOption('background', 'w') 
pg.setConfigOption('foreground', 'k') 

df = pd.DataFrame(np.random.randint(
    0, 10, size=(1000, 11)), columns=list('ABCDEFGHIJK')) 

win = pg.GraphicsWindow(title="Basic plotting examples") 
# win.resize(900, 600) 
win.setWindowTitle('pyqtgraph example: Plotting') 

# Enable antialiasing for prettier plots 
pg.setConfigOptions(antialias=True) 

ndays = 5 
ngenos = df.shape[1] 
nrows = 3 
ncols = 4 
p = ['p%s' % s for s in range(ngenos)] 
bg = ['bg%s' % s for s in range(ngenos * ndays)] 
font = QtGui.QFont() 
font.setPixelSize(5) 

for i in range(nrows): 
    for j in range(ncols): 
     if (i * ncols + j) < ngenos: 
      p[i * ncols + j] = win.addPlot(title=df.dtypes.index[i * ncols + j]) 
      for k in range(ndays): 
       bg[(i * ncols + j) + k] = pg.BarGraphItem(x=range(200), y0=(10 * k), height=df.iloc[: 200*(k+1), (i * ncols + j)], width=0.3) 
       p[i * ncols + j].addItem(bg[(i * ncols + j) + k]) 
      # p[i * ncols + j].showGrid(x=None, y=True) 
      p[i * ncols + j].setRange(xRange=(0, 200), yRange=(0, 60)) 
      p[i * ncols + j].getAxis('bottom').tickFont = font 
      p[i * ncols + j].getAxis('left').tickFont = font 

    win.nextRow() 


QtGui.QApplication.processEvents() 
ex = pg.exporters.SVGExporter(win.scene()) 
ex.export('test2.svg') 
ex = pg.exporters.ImageExporter(win.scene()) 
ex.export('test2.png') 

pg.cleanup 

if __name__ == '__main__': 
    import sys 
    if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'): 
     QtGui.QApplication.instance().exec_() 

PNG文件看起来很好,但分辨率很低。在SVG文件中,似乎所有的轴都发生了变化。

PNG文件: enter image description here

SVG文件: enter image description here

我怎么能做出SVG进出口权?谢谢!

回答

1

我检查并得到与您一样的输出。

这是PyQtGraph中的一个已经报告过的错误:see issue #434

在SVG导出中似乎还有一些长期存在的问题(问题105176),所以我不会指望快速修复。

也许你可以尝试自己去尝试一下。在SVGExporter.py中有一些后处理工作可以解决Qt的SVG生成器的一些问题,我的直觉是错误在那里。

+0

谢谢!希望他们能尽快解决它。 – Kevin