<p>Take a look at these <a href="https://www.kaggle.com/tigurius/recuplots-and-cnns-for-time-series-classification" rel="nofollow noreferrer">kaggle challange</a>. It think you also want to implement parts of <a href="https://arxiv.org/pdf/1710.00886.pdf" rel="nofollow noreferrer">this paper</a> like they do.</p>

<p>Maybe you can also use the function that they adopted from another SO question:</p>

<pre><code>#modified from https://stackoverflow.com/questions/33650371/recurrence-plot-in-python
def recurrence_plot(s, eps=None, steps=None):
    if eps==None: eps=0.1
    if steps==None: steps=10
    d = sk.metrics.pairwise.pairwise_distances(s)
    d = np.floor(d / eps)
    d[d &gt; steps] = steps
    #Z = squareform(d)
    return d
</code></pre>
Convert timeseries to image matrix
<p>I have a numpy array X of timeserieses. Something like that:</p>

<pre><code>[[0.05, -0.021, 0.003, 0.025, -0.001, -0.023, 0.095, 0.001, -0.018]
[0.015, 0.011, -0.032, -0.044, -0.002, 0.032, -0.051, -0.03, -0.020]
[0.04, 0.081, -0.02, 0.014, 0.063, -0.077, 0.059, 0.031, 0.025]]
</code></pre>

<p>I can plot this with</p>

<pre><code>fig, axes = plt.subplots(3, 1)
for i in range(3):
    axes[i].plot(X[i])
plt.show()
</code></pre>

<p>Then something like the following appears (the plots do <strong>not</strong> show the demo values I wrote above but other values with similar structure). So each row in X is one timeseries.
<a href="https://i.stack.imgur.com/lKykf.png" rel="noreferrer"><img src="https://i.stack.imgur.com/lKykf.png" alt="enter image description here"></a></p>

<p>But I want to have a numpy array which describes each timeseries as a grayscale image (because I want to use it for a cnn later). So I think what I need should be something like that:</p>

<pre><code>[[[0, 0, 0, 0, 0, 1]
[0, 0, 0, 0, 1, 0]
[0, 0, 0, 0, 0, 1]
[0, 0, 1, 0, 0, 0]]
[[0, 0, 1, 0, 0, 0]
[0, 0, 0, 1, 0, 0]
[0, 1, 0, 0, 0, 0]
[0, 1, 0, 0, 0, 0]]...]
</code></pre>

<p>How is it (if possible: efficiently) possible to convert each timeseries into a matrix, which describes the timeseries as an image. So each row in the old array (e.g. this: </p>

<p><code>[0.05, -0.021, 0.003, 0.025, -0.001, -0.023, 0.095, 0.001, -0.018]</code>) </p>

<p>should be converted to a 2D matrix (e.g. something like this: </p>

<p><code>[[0, 0, 0, 0, 0, 1]
[0, 0, 0, 0, 1, 0]
[0, 0, 0, 0, 0, 1]
[0, 0, 1, 0, 0, 0]]</code></p>

<p><strong>Alternative describtion:</strong>
Every row in X describes one timeseries. For each row in X I need a 2D matrix describing the timeseries as an image (like the plot shown above)</p>

<p><strong>"Solution"</strong>: Seems there is no nice solution to do this. I used this workaround now: </p>

<pre><code>fig = plt.figure()
fig.add_subplot(111)
fig.tight_layout(pad=0)
plt.axis('off')
plt.plot(X[0], linewidth=3)
fig.canvas.draw()
data = np.fromstring(fig.canvas.tostring_rgb(), dtype=np.uint8, sep='')
data = data.reshape(fig.canvas.get_width_height()[::-1] + (3,))
</code></pre>

<p>The <code>data</code> contains the 2D matrix now and could be plotted with <code>plt.imshow(data)</code> again with some loss of quality.</p>