|
| 1 | +# flake8: noqa |
| 2 | + |
| 3 | +import marimo |
| 4 | + |
| 5 | +__generated_with = "0.13.6" |
| 6 | +app = marimo.App(width="medium") |
| 7 | + |
| 8 | + |
| 9 | +@app.cell |
| 10 | +def _(): |
| 11 | + import marimo as mo |
| 12 | + import matplotlib.pyplot as plt |
| 13 | + |
| 14 | + return mo, plt |
| 15 | + |
| 16 | + |
| 17 | +@app.cell |
| 18 | +def _(ui_fixed_cost, ui_quantity, ui_selling_price, ui_unit_cost): |
| 19 | + fixed_cost = int(ui_fixed_cost.value) |
| 20 | + unit_cost = ui_unit_cost.value |
| 21 | + selling_price = float(ui_selling_price.value) |
| 22 | + upper_production_quantity = ui_quantity.value |
| 23 | + return fixed_cost, selling_price, unit_cost, upper_production_quantity |
| 24 | + |
| 25 | + |
| 26 | +@app.cell |
| 27 | +def _( |
| 28 | + fixed_cost, |
| 29 | + plt, |
| 30 | + selling_price, |
| 31 | + ui_break_even, |
| 32 | + ui_plot_color, |
| 33 | + unit_cost, |
| 34 | + upper_production_quantity, |
| 35 | +): |
| 36 | + break_even_quantity = fixed_cost / (selling_price - unit_cost) |
| 37 | + break_even_income = break_even_quantity * selling_price |
| 38 | + |
| 39 | + units = range(0, upper_production_quantity + 1, 1000) |
| 40 | + total_costs = [(unit * unit_cost) + fixed_cost for unit in units] |
| 41 | + sales_income = [unit * selling_price for unit in units] |
| 42 | + |
| 43 | + plt.plot(units, total_costs, marker="o", color=ui_plot_color.value) |
| 44 | + plt.plot(units, sales_income, marker="x") |
| 45 | + |
| 46 | + plt.xlabel("Units Produced") |
| 47 | + plt.ylabel("($)") |
| 48 | + plt.legend(["Total Costs", "Total Income"]) |
| 49 | + plt.title("Break-Even Analysis") |
| 50 | + |
| 51 | + if ui_break_even.value: |
| 52 | + plt.vlines( |
| 53 | + break_even_quantity, |
| 54 | + ymin=100, |
| 55 | + ymax=break_even_income, |
| 56 | + linestyles="dashed", |
| 57 | + ) |
| 58 | + |
| 59 | + plt.text( |
| 60 | + x=break_even_quantity + 100, |
| 61 | + y=int(break_even_income / 2), |
| 62 | + s=int(break_even_quantity), |
| 63 | + ) |
| 64 | + |
| 65 | + plt.grid() |
| 66 | + plt.show() |
| 67 | + return |
| 68 | + |
| 69 | + |
| 70 | +@app.cell |
| 71 | +def _(mo): |
| 72 | + ui_fixed_cost = mo.ui.radio(options=["40000", "50000"], value="50000") |
| 73 | + ui_unit_cost = mo.ui.slider(start=2, stop=5, step=1) |
| 74 | + ui_selling_price = mo.ui.text(value="10") |
| 75 | + ui_quantity = mo.ui.dropdown( |
| 76 | + options={"10000": 10000, "12000": 12000, "15000": 15000}, value="10000" |
| 77 | + ) |
| 78 | + ui_break_even = mo.ui.switch() |
| 79 | + ui_plot_color = mo.ui.dropdown( |
| 80 | + options={"Red": "red", "Green": "green", "Blue": "blue"}, value="Red" |
| 81 | + ) |
| 82 | + |
| 83 | + mo.md( |
| 84 | + f""" |
| 85 | + Fixed Costs: {ui_fixed_cost} |
| 86 | +
|
| 87 | + Unit Cost Price: {ui_unit_cost} |
| 88 | +
|
| 89 | + Selling Price: {ui_selling_price} |
| 90 | +
|
| 91 | + Maximum Quantity: {ui_quantity} |
| 92 | +
|
| 93 | + Display Break-Even Data: {ui_break_even} |
| 94 | +
|
| 95 | + Total Costs Plot Color: {ui_plot_color} |
| 96 | + """ |
| 97 | + ) |
| 98 | + return ( |
| 99 | + ui_break_even, |
| 100 | + ui_fixed_cost, |
| 101 | + ui_plot_color, |
| 102 | + ui_quantity, |
| 103 | + ui_selling_price, |
| 104 | + ui_unit_cost, |
| 105 | + ) |
| 106 | + |
| 107 | + |
| 108 | +if __name__ == "__main__": |
| 109 | + app.run() |
0 commit comments