pythonmatplotlibplotperiodicity

plotting repeated periodic solution


I am trying to plot a repeated periodic solution using matplotlib in python. I have the solution for one period, I have provided a sample test code below of the individual plot:

import matplotlib
import numpy as np
from matplotlib import pyplot as plt

File1 = np.genfromtxt('File1.dat')

fig,(ax1) = plt.subplots()
fig.subplots_adjust(hspace=1.0)

A1 = ax1.imshow(File1.T,extent=[-1,1,-1,1],cmap='coolwarm',origin='lower')
cbar = fig.colorbar(A1,orientation = 'vertical')

ax1.set_xticks([-1,0.0,1],minor=False)
ax1.set_yticks([-1,0.0,1],minor=False)
ax1.set_yticklabels(['$-1$','$0$','$1$'],minor=False)
ax1.set_yticklabels(['$-1$','$0$','$1$'],minor=False)

plt.xlabel('x', fontsize=22)
plt.ylabel('y', fontsize=22)
plt.title('Title', fontsize = 24)

plt.show()

where the sample .dat file, File1.dat is given by

0.863  0.863  0.863  
0.863  0.610  0.863  
0.863  0.863  0.863 

I want to plot this periodic solution now repeatedly on the same plot. To be specific, this plot ranges from x = [-1,1] and y = [-1,1], but I want to make it range from x = [-20,20] and y = [-20,20] repeating this same solution over and over (periodically).

How can I code this efficiently?

Copying the data in the .dat file may work for this simple example but my actual .dat file is very large and that method just isn't efficient. Thanks!


Solution

  • You probably want to plot

    imshow(np.tile(File1.T, (20,20)), extent=[-20,20,-20,20])
    

    See numpy.tile documentation.