Giter Site home page Giter Site logo

Improve stacked_bar.py about cost-reporter HOT 6 CLOSED

gruebel avatar gruebel commented on June 12, 2024
Improve stacked_bar.py

from cost-reporter.

Comments (6)

gruebel avatar gruebel commented on June 12, 2024
  1. Python uses snake_case for variable names

from cost-reporter.

gruebel avatar gruebel commented on June 12, 2024
  1. List comprehension is not needed here
    bottom = [0 for x in r]
bottom = [0] * days

from cost-reporter.

gruebel avatar gruebel commented on June 12, 2024
  1. Instead of using a separate index variable (x)
    x = 0
    for label in all_bars.keys():
    # There is nothing below the first bar, skip it for the first iteration
    if x > 0:
    print(previous_bar)
    bottom = np.add(bottom, previous_bar).tolist()
    plt.bar(r, all_bars[label], bottom=bottom, color=COLORS[x], edgecolor=edgecolor, width=barWidth, label=label)
    x += 1
    previous_bar = all_bars[label]

    it can be done with enumerate()
    for idx, label in enumerate(all_bars.keys()):
        # There is nothing below the first bar, skip it for the first iteration
        if idx > 0:
            print(previous_bar)
            bottom = np.add(bottom, previous_bar).tolist()

        plt.bar(r, all_bars[label], bottom=bottom, color=COLORS[idx], edgecolor=edgecolor, width=barWidth, label=label)
        previous_bar = all_bars[label]

from cost-reporter.

gruebel avatar gruebel commented on June 12, 2024
  1. if this should be really logged, then use proper logging

from cost-reporter.

gruebel avatar gruebel commented on June 12, 2024
  1. it is always better to use pathlib module to define a filesystem path to make it OS independent
    plt.savefig('/tmp/image.png', bbox_inches='tight')

from cost-reporter.

flyck avatar flyck commented on June 12, 2024

done, thanks

from cost-reporter.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.