Skip to content

Plotting

Marinna Martini edited this page Apr 24, 2020 · 9 revisions

Here is my current favorite matplotlib plot setup, a code fragment reminder for now:

lines = []
fig, axes = plt.subplots(figsize=(15,2))
lines.append(axes.plot(t[0],ds[0]['wh_4061'][:,0,0],color='g',label=lbls[0]))
lines.append(axes.plot(t[1],ds[1]['wh_4061'][:,0,0],color='b',linestyle=':',label=lbls[1]))
lines.append(axes.plot(t[2],ds[2]['wh_4061'][:],color='r',label=lbls[2]))

#axes.set_ylim(10,14)
#axes.set_xlim(pydt[0],pydt[-1])
#axes.set_xlim(pydt[0],pydt[-1])
#axes.set_title('T_28')
axes.legend(loc='best')

the setup might also be

fig = plt.figure(figsize=(15,5))
ax = fig.add_subplot()

Another variant is

fig, ax = plt.subplots(figsize=(15,2))
ax.plot(ds['time'][burst_number,:],ds[var][burst_number,:])
ax.set(xlabel='sec')
ax.set(ylabel=ds[var].units)
ax.set(title=f'burst {burst_number} on {cft[burst_number]} in {infileroot[1:]}')

A pcolor variant is this, a sonar image from a processed sonar file

img = ds['sonar_image'][19,0,:,:]
x = ds['x'][:]
y = ds['y'][:]

fig, ax = plt.subplots(1,1,figsize=(5,5))

c = ax.pcolormesh(x,y,img, cmap='gray')
ax.set_title(f'Imagenex 881a HF Sonar Image {t[idx[0]]:%Y-%m-%d}')
ax.set_xlabel('meters')
ax.set_ylabel('meters')
ax.axis('equal')

plt.show()

Saving these files is done by:

# note that we use fig as the figure object, not plt, which was shown in an example
fig.savefig('fig11_hffanimage.eps', format='eps')
Clone this wiki locally