Python Forum
[PyQt] Assign Label Text as number in Hz
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] Assign Label Text as number in Hz
#7
I have no clue about music.
Based on this Article and this Example with matplotlib, I wrote an example.

from itertools import product
import matplotlib.pyplot as plt


def calc_freq_from_midi(m):
    if m < 0 or m > 127:
        raise ValueError('m must be between 0 and 127.')
    notes = ('C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B')
    octaves = range(-1, 10)
    notes = product(octaves, notes)
    notes = [note + str(band) for band, note in notes]
    freq = 440 * 2 ** ((m - 69)/12)
    return freq, notes[m]

labels = [calc_freq_from_midi(m) for m in range(128)]
x_ticks, x_labels = zip(*labels) # it's a transpose


frequencies = [110.0, 220.0, 440.0] # A2, A3, A4
magnitude = [2, 3, 4]
plt.title('Spectrum')
plt.xlabel('Notes')
plt.ylabel('Magnitude')
plt.xticks(x_ticks, x_labels, rotation='vertical')
plt.plot(frequencies, magnitude, 'o')
plt.legend(['Signal'])
plt.show()
Just check if the notes are correct.
It should plot A2, A3 and A4 as blue dots.

I guess you can also print two different xticks.
Just explore the matplotlib examples.

If you don't use matplotlib inside of QT, you have to adapt it to the plotting framework you use.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Messages In This Thread
Assign Label Text as number in Hz - by mekha - Jul-01-2018, 12:45 PM
RE: Assign Label Text as number in Hz - by Alfalfa - Jul-01-2018, 05:28 PM
RE: Assign Label Text as number in Hz - by mekha - Jul-01-2018, 11:12 PM
RE: Assign Label Text as number in Hz - by Alfalfa - Jul-03-2018, 04:17 PM
RE: Assign Label Text as number in Hz - by mekha - Jul-04-2018, 01:44 AM
RE: Assign Label Text as number in Hz - by mekha - Jul-07-2018, 02:44 AM
RE: Assign Label Text as number in Hz - by Alfalfa - Jul-10-2018, 04:26 PM
RE: Assign Label Text as number in Hz - by mekha - Jul-11-2018, 04:18 AM
RE: Assign Label Text as number in Hz - by DeaD_EyE - Jul-03-2018, 10:02 PM
RE: Assign Label Text as number in Hz - by mekha - Jul-07-2018, 01:14 AM
RE: Assign Label Text as number in Hz - by DeaD_EyE - Jul-04-2018, 10:30 AM
RE: Assign Label Text as number in Hz - by mekha - Jul-12-2018, 01:48 PM
RE: Assign Label Text as number in Hz - by Alfalfa - Jul-12-2018, 09:38 PM
RE: Assign Label Text as number in Hz - by mekha - Jul-16-2018, 11:39 AM
RE: Assign Label Text as number in Hz - by Alfalfa - Jul-16-2018, 12:45 PM
RE: Assign Label Text as number in Hz - by mekha - Jul-16-2018, 01:59 PM
RE: Assign Label Text as number in Hz - by Alfalfa - Jul-16-2018, 04:35 PM
RE: Assign Label Text as number in Hz - by mekha - Jul-18-2018, 12:47 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] The Text in the Label widget Tkinter cuts off the Long text in the view malmustafa 4 5,314 Jun-26-2022, 06:26 PM
Last Post: menator01
  update text variable on label with keypress knoxvilles_joker 3 5,091 Apr-17-2021, 11:21 PM
Last Post: knoxvilles_joker
  How to read text in kivy textinput or Label jadel440 1 5,391 Dec-29-2020, 10:47 AM
Last Post: joe_momma
  Tkinter: How to assign calculated value to a Label LoneStar 7 4,047 Sep-03-2020, 08:19 PM
Last Post: LoneStar
  [Kivy] Kivy text label won't shows up! AVD_01 1 3,002 Jun-21-2020, 04:01 PM
Last Post: AVD_01
  [Tkinter] Python 3 change label text gw1500se 6 4,843 May-08-2020, 05:47 PM
Last Post: deanhystad
  [Tkinter] how to update label text from list Roshan 8 5,628 Apr-25-2020, 08:04 AM
Last Post: Roshan
  [PyQt] Python PyQt5 - Change label text dynamically based on user Input ppel123 1 13,880 Mar-20-2020, 07:21 AM
Last Post: deanhystad
  [Tkinter] Label, align imported text from pandas kundrius 2 4,324 Dec-11-2019, 08:26 AM
Last Post: kundrius
  Make Label Text background (default color) transparent using tkinter in python barry76 1 24,233 Nov-28-2019, 10:19 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020