社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
私信  •  关注

gboffi

gboffi 最近创建的主题
gboffi 最近回复了

enter image description here

这里是一个非Plotly解决方案,只是Matplotlib。

读者可以理解,如何在代码中轻松计算出正确的杆间距和位置。

In [102]: import matplotlib.pyplot as plt
     ...: from random import randint
     ...: 
     ...: # faking some data
     ...: dow = 'Mon Tue Wed Thu Fri'.split()
     ...: emps = 'Concetta Laura Gerry Ceci'.split()
     ...: data = {e:{d:(randint(0,12),randint(6,12))for d in dow}for e in emps}
     ...: 
     ...: # computing the appropriate width of the bars
     ...: nbars = len(emps)
     ...: d = 0.25   # distance between bars in terms of the bar width
     ...: total_width = 0.80 # total width of the horizontal stack of bars
     ...: # total_width = nbars*w + (nbars-1)*d*w →
     ...: w = total_width/(nbars+(nbars-1)*d)
     ...: origin = -total_width/2
     ...: 
     ...: # Plotting
     ...: x = range(len(dow))
     ...: fig, ax = plt.subplots()
     ...: for n, (emp, hours) in enumerate(data.items()):
     ...:     xn = [_+origin+n*(1+d)*w for _ in x]
     ...:     bottoms, heights = zip(*hours.values())
     ...:     ax.bar(xn, heights, width=w,
     ...:            bottom=bottoms, align='edge', label=emp)
     ...: # add background to groups of bars
     ...: ax.bar(x, 24, (total_width+1)/2, bottom=0, zorder=0, alpha=0.15)
     ...: # fixing x tick labels
     ...: ax.set_xticks(range(len(dow)))
     ...: ax.set_xticklabels(dow)
     ...: # fix y axis
     ...: ax.set_ylim((-0.50, 24.50))
     ...: ax.set_yticks(range(0, 25, 2))
     ...: # 
     ...: fig.legend()
     ...: plt.show()
7 年前
回复了 gboffi 创建的主题 » 在python中添加两个二进制数

一些建议

  1. 规范化位字符串的长度

    l0, l1 = map(len, (str0, str1))
    if l0 < l1:
        str0 = "0"*(l1-l0) + str0
    elif l1 < l0:
        str1 = "0"*(l0-l1) + str1
    
  2. 对反向字符串元素执行循环并自下而上构造二进制字符串

    remainder = 0
    result = ""
    for bit_0, bit1 in zip(reversed(str0), reversed(str1)):
        bit_0, bit_1 = map(int, (bit_0, bit_1))
        new_bit, remainder = f(bit_0, bit_1, remainder)
        result = str(new_bit) + result
    if remainder != 0
        ...
    

写作 f(bit_0, bit_1, remainder) 以及处理如果 remainder 不为空在循环结束时保留为练习。