path = sys.path[0] + '/' fileNameOnly = generalUtility.getFileNameOnly(fName) # calculate the Intensity data using Praat dataT, dataI = praatUtil.calculateIntensity(path + fName) # normalize the dB data, since it's not calibrated dataI -= dataI.max() # generate the graph graph = matplotlibUtil.CGraph(width = 8, height = 3) graph.createFigure() ax = graph.getArrAx()[0] ax.plot(dataT, dataI, linewidth = 2) ax.set_xlabel("Time [s]") ax.set_ylabel("SPL [dB]") ax.set_title(fileNameOnly) graph.padding = 0.1 graph.adjustPadding(bottom = 2, right = 0.5) ax.grid() # It is not aesthetically pleasing when graph data goes to all the way to the # upper and lower edges of the graph. I prefer to have a little space. matplotlibUtil.setLimit(ax, dataI, 'y', rangeMultiplier = 0.1) # every doubling of sound pressure level (SPL) results in an increase of SPL by # 6 dB. Therefore, we need to change the y-axis ticks matplotlibUtil.formatAxisTicks(ax, 'y', 6, '%d') # finally, save the graph to a file plt.savefig(fileNameOnly + "_intensity.png")
############################## # ----- PANELS 2 and 3 ----- # ############################## # extract parts of the data and plot in next row n = len(arrData) for i in range(2): idx1 = (n / 2) * i idx2 = idx1 + n / 4 ax = arrAx[i + 1] ax.plot(arrT[idx1:idx2], arrData[idx1:idx2], linewidth = graph.lineWidth) ax.grid() ax.set_xlabel("Time [s]") ax.set_ylabel("Amplitude") matplotlibUtil.setLimit(ax, arrData[idx1:idx2], 'y', 0.1) ####################### # ----- PANEL 4 ----- # ####################### # create a noisy data distribution and plot in bottom left panel. fit a # polinomial to the data n = 100 arrX = range(n) arrY = numpy.zeros(n) for i in arrX: arrY[i] = numpy.sqrt(i) + numpy.random.random() * 3 ax = arrAx[-2]