C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6 MSBUILD

# plotting frequency in x-axis

Date : November 17 2020, 07:01 PM
Hope that helps I have to plot a an inverted v or tent shaped curve (Laplacian).
code :
``````import numpy as np
import matplotlib.pyplot as plt
x = np.random.normal(scale=5, size=50000) # create example data
bins = np.linspace(-15, 15, 31) # make bins to count occurrences within
counts, bins = np.histogram(x, bins) # do the counting
# counts is the number of occurences of x in each bin
bins = (bins[1:]+bins[:-1])/2.0 # take the midpoints of the bins for plotting
plt.loglog(bins, counts) # you'll only get the triangle shape in log-log space
``````

Share :

## Plotting histograms with R; y axis keeps changing to frequency from proportion/probability

By : Bill Manning
Date : March 29 2020, 07:55 AM
this one helps. When you call plot on an object of class histogram (like c1), it calls the S3 method for the histogram. Namely, plot.histogram. You can see the code for this function if you type graphics:::plot.histogram and you can see its help under ?plot.histogram. The help file for that function states:
code :
``````plot(c1, col=rgb(1,0,0,1/4), xlim=c(minx,maxx), main=paste(paramlab,"Group",groupnum,sep=" "),xlab="",freq=FALSE)# first histogram
``````

## Confusion on how the frequency axis when plotting the FFT magnitude is created

By : Raman Chhabra
Date : March 29 2020, 07:55 AM
I hope this helps . The reason why the range is between [-Fs/2,Fs/2] is because Fs/2 is the Nyquist frequency. This is the largest possible frequency that has the ability of being visualized and what is ultimately present in your frequency decomposition. I also disagree with your comment where the range "could be between [-0.25,0.25]". This is contrary to the definition of the Nyquist frequency.
From signal processing theory, we know that we must sample by at least twice the bandwidth of the signal in order to properly reconstruct the signal. The bandwidth is defined as the largest possible frequency component that can be seen in your signal, which is also called the Nyquist Frequency. In other words:
code :
``````Fs = 2*BW
``````
``````BW = Fs / 2;
``````
``````f = i * Fs / N, for i = 0, 1, 2, ..., N-1
``````
``````freqaxis=Fs*(linspace(-0.5,0.5, 513); %// Change
freqaxis(end) = []; %// Change
``````
``````freqaxis = linspace(-Fs/2, Fs/2, 513);
freqaxis(end) = [];
``````

## Plotting a histogram with ggplot with only x values and frequency count, instead of usual frequency vector

By : Jae yeong
Date : March 29 2020, 07:55 AM
Hope that helps I have a dataframe for my for variable X, with the corresponding count of how many times each X value appears: , You can use stat="identity" with geom_bar.
e.g.
code :
``````testdt <- data.frame(x = c(1,2,3,4,5,6), count = c(10, 20, 10, 5, 15, 25))
ggplot(data = testdt) + geom_bar(aes(x = x, y = count), stat = "identity")
``````

## Displaying y-axis in percentage format when plotting conditional frequency distibution

By : Hrishikesh Bharali
Date : March 29 2020, 07:55 AM
like below fixes the issue When plotting conditional frequency distribution for some set of words in text corpora, y-axis is displayed as counts, not percentages , Here is a solution which will provide the output you are looking for:
code :
``````inltk.download('udhr')
import pandas as pd
from nltk.corpus import udhr

languages = ['Chickasaw', 'English', 'German_Deutsch', 'Greenlandic_Inuktikut', 'Hungarian_Magyar', 'Ibibio_Efik']

cfd = nltk.ConditionalFreqDist(
(lang, len(word))
for lang in languages
for word in udhr.words(lang + '-Latin1'))

def plot_freq(lang):
max_length = max([len(word) for word in udhr.words(lang + '-Latin1')])
eng_freq_dist = {}

for i in range(max_length + 1):
eng_freq_dist[i] = cfd[lang].freq(i)

ed = pd.Series(eng_freq_dist, name=lang)

ed.cumsum().plot(legend=True, title='Cumulative Distribution of Word Lengths')
``````
``````for lang in languages:
plot_freq(lang)
``````

## Plotting respiration signal in frequency domain on y axis while time is on x axis

By : Jason Li
Date : March 29 2020, 07:55 AM
wish helps you I have a respiration (breathing) signal and a sampling frequency of 25 Hz and need to detect where is the lowest breathing frequency on a time scale, which should tell me actually when the person became sleepy. Fourier transforms in its classical form doesn't give me much useful information. So, to clarify: the time of measurement should be on the x-axis and the breathing frequency should be on the y-axis. Then, I suppose, lower amplitudes of the signal will show the slower breathing. What should be done with the signal to plot it the way I need? , All credits for this code go to Star Strider.
code :
`````` D = load('respiratory.txt');
Fs = 25;                                                    % Sampling Frequency (Hz)
Fn = Fs/2;                                                  % Nyquist Frequency
Ts = 1/Fs;                                                  % Sampling Time (sec)
L = numel(D);
t = linspace(0, L, L)*Ts;                                   % Time Vector (sec)

figure(1)
plot(t, D)
grid
% axis([0  60    -850  -750])
axis([xlim    -850  -750])
xlabel('Time')
ylabel('Amplitude')

FTD = fft(D-mean(D))/L;                                     % Fourier Transform
Fv = linspace(0, 1, fix(L/2)+1)*Fn;                         % Frequency Vector
Iv = 1:numel(Fv);                                           % Index Vector

figure(2)
plot(Fv, abs(FTD(Iv))*2)
grid
axis([0  2.5    ylim])
xlabel('Frequency (Hz)')
ylabel('Amplitude')

Wp = [0.35 0.65]/Fn;                                        % Passband Frequency (Normalised)
Ws = [0.30 0.75]/Fn;                                        % Stopband Frequency (Normalised)
Rp =   1;                                                   % Passband Ripple (dB)
Rs =  50;                                                   % Stopband Ripple (dB)
[n,Ws]  = cheb2ord(Wp,Ws,Rp,Rs);                            % Filter Order
[z,p,k] = cheby2(n,Rs,Ws);                                  % Filter Design, Sepcify Bandpass
[sos,g] = zp2sos(z,p,k);                                    % Convert To Second-Order-Section For Stability

figure(3)
freqz(sos, 2^16, Fs)                                        % Filter Bode Plot

D_filtered = filtfilt(sos, g, D);                           % Filter Signal

[pks,locs] = findpeaks(D_filtered, 'MinPeakDist',40);

figure(4)
plot(t, D_filtered)
hold on
plot(t(locs), pks, '^r')
hold off
grid
% axis([0  60    ylim])
axis([0  60    -15  15])
xlabel('Time')
ylabel('Amplitude')

tdif = diff([0 t(locs)]);                                   % Time Difference Between Peaks (sec)
Dfrq = 60./tdif;                                            % Frequency (Respirations/Minute)

figure(5)
plot(t(locs), Dfrq)
grid
axis([xlim    10  40])
xlabel('Time (sec)')
ylabel('Frequency (minute^{-1})')
``````