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