Python-A way to show digital patterns(bits) in Matplotlib

Presentation on a way to show digital patterns (bits) visually in Matplotlib

drawstyle was helpful but did not show the pattern correctly 100%(for me)

below is my presentation followed by the code.

Presentation

Python Code Text

# -*- coding: utf-8 -*-
"""
Created on Fri May 19 21:01:14 2023

@author: aleja
"""

import matplotlib.pyplot as plt

#this demo uses same size bits for all data
#real data (you will use for any processing _ the visual data is only for plots)
data0=[1,1,1,1,0,0,0,0]
data1=[1,1,0,0,0,0,0,0]
data2=[1,0,1,0,1,0,1,0]
data3=[0,0,0,0,1,1,1,1]
data4=[0,0,0,0,0,0,0,1]
plots=[data0,data1,data2,data3,data4] #show this digital pattern

#the many step way to make [0-------n] in data1
# x_data_pt=[]
# x= len(data1)
# print(x) 
# for i in range(x):   
#     x_data_pt.append(i)
# print (x_data_pt)
#fix my plot so it looks ok (fix width digital bit)
def Make_My_Dig_Plot_look_ok(datas_holder):
    data_long=[]
    visual_plots=[]
    for n,data in enumerate(plots):
        data_long=[]
        for bit in data:        
            for i in range(1):
             data_long.append(bit)
        data_long.append(bit)
        visual_plots.insert(n,data_long)
    print(visual_plots)
    return visual_plots        #for visual

new_plots=Make_My_Dig_Plot_look_ok(plots)
x_data_pt = [(i-0.5) for i in range(len(new_plots[0]))]  #the one line way and a slight 1/2 bit shift 
# print(x_data_pt)
plt.clf()
plt.close()
fig,axs=plt.subplots(len(new_plots),sharex=True)  # add sharex if you dont want all x axis number on each, odd but works num="Title"
mngr = plt.get_current_fig_manager()
mngr.window.setGeometry(20,60,640, 545)  #Location and size
mngr.window.setWindowTitle("A way to show digital bits multiple patterns")  #I am using this way to put title on figure window
# https://stackoverflow.com/questions/38307438/set-matplotlib-default-figure-window-title
fig.suptitle('Digitial Pattern', fontsize=16)
for plotnum in range(len(plots)):
#     #none of these are exactly what i want with the Origianl data is the closest but its chops the left and right half width (dont like that look)
#     with the function fixing step=post is the best for me
      #if plotnum==0:axs[plotnum].set_title("Digital Patterns")
      axs[plotnum].plot(x_data_pt,new_plots[plotnum],drawstyle="steps-post")
      axs[plotnum].set_ylabel("Data"+str(plotnum))  #how to put y axis label
#     axs[plotnum].plot(x_data_pt,plots[plotnum],drawstyle="steps-mid") #almost right but chops my least significant bit and most sig bit width
#     #axs[plotnum].plot(x_data_pt,plots[plotnum],drawstyle="steps-pre")
#     #axs[plotnum].plot(x_data_pt,plots[plotnum],drawstyle="steps")
    
    

Python Code Zip

Notes

  • Presentation: Showing a possible way to show digital pattern (bits) in Matplotlib
  • Programming Language used: Python 3.9 in Spyder5.4.3,Matplotlib 3.7.1
  • Presentation app: Microsoft’s PowerPoint
  • Helpful resource: Stackoverflow, Search Engines , Bing chat AI, and Python communities.
  • Bing is a Microsoft’s product.
  • Python, Tkinter, and Matplotlib are products of respective companies
  • Presentation shown to spark ideas of use.
  • This presentation is not connected to or endorsed by any company.
  • Use at your own risk.
  • Tags: Python, Python3.9, Matplotlib , Digital (bits) Patterns
  • Title Tag: Showing ‘a’ possible way to show digital pattern (bits) in Matplotlib

About LV_TS_Test_Engineer_3000_VI

Automated Test Equipment Software
This entry was posted in Test Sector and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s