# [Tutor] Python question

Eleonora Panini eleonora.panini7jkd at gmail.com
Wed Apr 20 14:39:15 EDT 2022

```Thank you for your suggestions..I have an other question:
Why my output plot is empty? The code is:

fig, ax = plt.subplots()
ax.set_title(f"Orbit={OrbitNumber}" + f"-Date={DATE[0]}" +
"-Burst mode high resolution -from FFT A131W wave form" )
x_lims = list(map( lambda x:x, d_time.Time))
x_lims = mdates.date2num(x_lims)
ext=[np.nanmin(x_lims),np.nanmax(x_lims),0,1024]
im = ax.imshow(70+20*np.log10(np.rot90(inter,2)),interpolation='None',cmap=
'jet',aspect='auto', extent=ext)
ax.set_xlabel('DateTime')
ax.set_ylabel('f [kHz]')
plt.ylim(0,1024)
x1=d_time.iloc[12]['Time']
x2=d_time.iloc[189]['Time']
y=np.arange(0,1025)
plt.fill_betweenx(y,x1,x2,facecolor="white")
x1=d_time.iloc[657]['Time']
x2=d_time.iloc[1076]['Time']
y=np.arange(0,1025)
plt.fill_betweenx(y,x1,x2,facecolor="white")
x1=d_time.iloc[0]['Time']
x2=d_time.iloc[10]['Time']
y=np.arange(0,1025)
plt.fill_betweenx(y,x1,x2,facecolor="white")
ax.xaxis.set_ticks_position("bottom")
ax.xaxis.set_label_position("bottom")
ax.xaxis_date()
ax.xaxis.set_major_formatter(mdates.DateFormatter('%H:%M'))
ax.xaxis.set_major_locator(mdates.MinuteLocator(interval=1))
d_time.plot( x='Time', y='Freq', ax=ax, alpha=0)
#plt.savefig("/content/drive/MyDrive/Colab
Notebooks/Plot/inter.png",bbox_inches = 'tight')
plt.rcParams["figure.figsize"] = (20,3)
plt.show()

These are the 2 columns of my dataframe 'd_time':
d_time = pd.DataFrame()
d_time['Time']=pd.date_range(start="2018-8-7 07:08:55.902",end=
"2018-8-7 07:46:01.813" ,freq="0.04S").values
d_time.Time = pd.to_datetime(d_time.Time)
d_time['Freq'] = np.arange(0,55648).tolist()

the array 'inter' is 1024x23400
The part of my code with iloc is to select the white zone of my plot

On Wed, 20 Apr 2022 at 01:55, Cameron Simpson <cs at cskk.id.au> wrote:

> On 18Apr2022 11:50, Eleonora Panini <eleonora.panini7jkd at gmail.com> wrote:
> ><https://stackoverflow.com/posts/71904558/timeline>
> >I need help to do the following steps in Phyton:
> >
> >-my starting array is: array = np.random.rand(1024x11700)
> >
> >-I have to obtain an array 1024x23400 with the following characteristics:
> >25 columns(1024x25) of data and 25 columns (1024x25) of zeros
> >
> > So I thought to do a loop every 25 columns(1024x25), insert an array of
> >zeros (1024x25) alternatevely every 25 columns, so I obtain an array
> >1024x23400..
> >
> >but I don't know how to do it in Phyton.. Can you help me? Thank you
>
> See Dennis' followup with suggested numpy functions which will help.
>
> My own naive approach would be to make a new array by alternatively
> concatentating your 25 rows of data, then 25 rows of zeroes (Dennis
> mentioned a .zeroes function), repeat until you have done the whole
> original array.
>
> I suggest you use a for-loop, using a range() to obtain the offsets you
> need: https://docs.python.org/3/library/stdtypes.html#range
> so the initial loop would look like this:
>
>     for offset in range(0, 11700, 25):
>
> which counts "offset" from 0 to 11700 (excluding the 11700) in steps of
> 25. That would let you grab the 25 rows of data at each offset and make
> an additional 25 rows of zeroes for building the second array.
>
> Cheers,
> Cameron Simpson <cs at cskk.id.au>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>

--
*Eleonora Panini*
*3480581404*
```