Skip to content

Commit 5aa7dfa

Browse files
committed
stash
1 parent 53bbffb commit 5aa7dfa

File tree

1 file changed

+44
-51
lines changed

1 file changed

+44
-51
lines changed

gnuplotlib.py

Lines changed: 44 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1680,7 +1680,7 @@ def _checkpoint(self, flags=''):
16801680
if self.processOptions.get('notest') and not waitforever and not final and not printwarnings:
16811681
return None, None
16821682

1683-
checkpoint = "gpsync{}xxx".format(self.sync_count)
1683+
checkpoint = f"gpsync{'final' if final else 'notfinal'}{self.sync_count}xxx"
16841684
self.sync_count += 1
16851685

16861686
self._printGnuplotPipe( 'print "{}"\n'.format(checkpoint) )
@@ -1691,7 +1691,7 @@ def _checkpoint(self, flags=''):
16911691
return '',[]
16921692

16931693
fromerr = ''
1694-
while not fromerr.endswith(checkpoint):
1694+
while not fromerr.endswith(checkpoint + '\n'):
16951695
# if no data received in 5 seconds, the gnuplot process is stuck. This
16961696
# usually happens if the gnuplot process is not in a command mode, but in
16971697
# a data-receiving mode. I'm careful to avoid this situation, but bugs in
@@ -1828,53 +1828,48 @@ def _plotCurveInASCII(self, curve):
18281828

18291829
def _sendCurve(self, curve):
18301830

1831-
pipe = self._gnuplotStdin()
1831+
with open("/tmp/gpipe", "wb") as pipe:
18321832

1833-
if self._plotCurveInASCII(curve):
1833+
if self._plotCurveInASCII(curve):
18341834

1835-
if curve.get('matrix'):
1836-
np.savetxt(pipe,
1837-
nps.glue(*curve['_data'], axis=-2).astype(np.float64,copy=False),
1838-
'%s')
1839-
self._printGnuplotPipe( "\ne\n" )
1835+
if curve.get('matrix'):
1836+
np.savetxt(pipe,
1837+
nps.glue(*curve['_data'], axis=-2).astype(np.float64,copy=False),
1838+
'%s')
1839+
else:
1840+
# Previously I was doing this:
1841+
# np.savetxt( pipe,
1842+
# nps.glue(*curve['_data'], axis=-2).transpose().astype(np.float64,copy=False),
1843+
# '%s' )
1844+
#
1845+
# That works in most cases, but sometimes we have disparate data
1846+
# types in each column, so glueing the components together into
1847+
# a single array is impossible (most notably when plotting 'with
1848+
# labels' at some particular locations). Thus I loop myself
1849+
# here. This is slow, but if we're plotting in ascii, we
1850+
# probably aren't looking for maximal performance here. And
1851+
# 'with labels' isn't super common
1852+
Ncurves = len(curve['_data'])
1853+
def write_element(e):
1854+
r'''Writes value to pipe. Encloses strings in "". This is required to support
1855+
labels with spaces in them
1856+
1857+
'''
1858+
if type(e) is np.string_ or type(e) is np.str_:
1859+
pipe.write(b'"')
1860+
pipe.write(str(e).encode())
1861+
pipe.write(b'"')
1862+
else:
1863+
pipe.write(str(e).encode())
1864+
1865+
for i in range(curve['_data'][0].shape[-1]):
1866+
for j in range(Ncurves-1):
1867+
write_element(curve['_data'][j][i])
1868+
pipe.write(b' ')
1869+
write_element(curve['_data'][Ncurves-1][i])
1870+
pipe.write(b'\n')
18401871
else:
1841-
# Previously I was doing this:
1842-
# np.savetxt( pipe,
1843-
# nps.glue(*curve['_data'], axis=-2).transpose().astype(np.float64,copy=False),
1844-
# '%s' )
1845-
#
1846-
# That works in most cases, but sometimes we have disparate data
1847-
# types in each column, so glueing the components together into
1848-
# a single array is impossible (most notably when plotting 'with
1849-
# labels' at some particular locations). Thus I loop myself
1850-
# here. This is slow, but if we're plotting in ascii, we
1851-
# probably aren't looking for maximal performance here. And
1852-
# 'with labels' isn't super common
1853-
Ncurves = len(curve['_data'])
1854-
def write_element(e):
1855-
r'''Writes value to pipe. Encloses strings in "". This is required to support
1856-
labels with spaces in them
1857-
1858-
'''
1859-
if type(e) is np.string_ or type(e) is np.str_:
1860-
pipe.write(b'"')
1861-
pipe.write(str(e).encode())
1862-
pipe.write(b'"')
1863-
else:
1864-
pipe.write(str(e).encode())
1865-
1866-
for i in range(curve['_data'][0].shape[-1]):
1867-
for j in range(Ncurves-1):
1868-
write_element(curve['_data'][j][i])
1869-
pipe.write(b' ')
1870-
write_element(curve['_data'][Ncurves-1][i])
1871-
pipe.write(b'\n')
1872-
1873-
1874-
self._printGnuplotPipe( "e\n" )
1875-
1876-
else:
1877-
nps.mv(nps.cat(*curve['_data']), 0, -1).astype(np.float64,copy=False).tofile(pipe)
1872+
nps.mv(nps.cat(*curve['_data']), 0, -1).astype(np.float64,copy=False).tofile(pipe)
18781873

18791874
self._logEvent("Sent the data to child process (not logged)")
18801875

@@ -1993,7 +1988,7 @@ def set_equation(equation, cmds):
19931988
for curve in curves:
19941989
optioncmds = optioncmd(curve)
19951990

1996-
plot_pipe_name = '-'
1991+
plot_pipe_name = f'<cat /tmp/gpipe'
19971992

19981993
if not self._plotCurveInASCII(curve):
19991994
# I get 2 formats: one real, and another to test the plot cmd, in case it
@@ -2033,11 +2028,10 @@ def set_equation(equation, cmds):
20332028

20342029
testData_curve = ''
20352030
if curve.get('matrix'):
2036-
testmatrix = "{0} {0}\n" + "{0} {0}\n" + "\ne\n"
2031+
testmatrix = "{0} {0}\n" + "{0} {0}\n\n"
20372032
testData_curve = testmatrix.format(testdataunit_ascii) * (curve['tuplesize'] - 2)
20382033
else:
2039-
testData_curve = ' '.join( ['{}'.format(testdataunit_ascii)] * curve['tuplesize']) + \
2040-
"\n" + "e\n"
2034+
testData_curve = ' '.join( ['{}'.format(testdataunit_ascii)] * curve['tuplesize']) + "\n"
20412035

20422036
testData += testData_curve
20432037

@@ -2385,7 +2379,6 @@ def plot_subplot(plotcmd, curves):
23852379
# ^
23862380
# line 0: invalid command
23872381
# ' while sending cmd 'set output'
2388-
self._printGnuplotPipe('\n\n\n\n')
23892382

23902383
def plot_process_footer():
23912384
if self.processOptions.get('terminal') == 'gp':

0 commit comments

Comments
 (0)