Drawing a silverstone curve using python

1. Silverstone Curve Visualization

This is the code to visualize the Maxy Silverstone curve with python. It has been confirmed to work with JupyterNotebook. The parameters currently included are super-appropriate, so please change and use them yourself.

fix_cost_simulator


import pandas as pd
import numpy as np
import math
import matplotlib.pyplot as plt
%matplotlib inline

# set investigation cost
PLANT_COST = 9_999_999_999 # set plant cost [!]
LINE_COST = 99_999_999     # set line cost [!]
TOOLING_COST = 69_999_999   # set tooling cost [!]

# set how much lines a plant will have [!]
PLANNED_NUM_OF_LINE = 8

# set each condition of the capacity. (pcs/yr = pcs/day * day/mo * mo/yr) 
LINE_DAILY_CAPA = 999 # set daily line production capacity [!]
TOOLING_DAILY_CAPA = 599 # set daily tooling production capacity [!]
DAYS_PER_MONTH = 22 # set working days [!]
MONTHS_PER_YEAR = 12 # how many months in a year
LINE_CAPA = LINE_DAILY_CAPA * DAYS_PER_MONTH * MONTHS_PER_YEAR # calc line capacity per year
TOOLING_CAPA = TOOLING_DAILY_CAPA * DAYS_PER_MONTH * MONTHS_PER_YEAR # calc tooling capacity per year

# set the condition for this simulation
START_QTY = 100_000 # starting point(production number) for this simulation
PLOT_WIDTH = 1_000 # plotting width
MARGIN_RATIO = 0.9 # set safety margin (consider a risk of sales) [!]
PLANT_DEP_YEAR = 9 # set plant depreciation year [!]
LINE_DEP_YEAR = 9 # set line depreciation year [!]
TOOLING_DEP_YEAR = 2.2 # set tooling depreciation year [!]
END_QTY = PLANNED_NUM_OF_LINE * LINE_CAPA # calc the end of this simulation

# initialize number of line/tooling
line_num = math.ceil(START_QTY / LINE_CAPA) # initialize number of line
tooling_num = math.ceil(START_QTY / TOOLING_CAPA) # initialize number of tooling

plant_dep_qty =  END_QTY * PLANT_DEP_YEAR * MARGIN_RATIO # calc plant depreciation quantity

# generate data for simulation
x_range = np.arange(START_QTY, END_QTY, PLOT_WIDTH)
Y = []
p_line_capa = line_num * LINE_CAPA # calc initial line production capacity
p_tooling_capa = tooling_num * TOOLING_CAPA # calc initial tooling production capacity
for x in x_range:
    if x > p_line_capa: # if production qty is over line capa, add a new line
        line_num += 1
        p_line_capa = line_num * LINE_CAPA
    if x > p_tooling_capa: # if production qty is over tooling capa, add a new tooling
        tooling_num += 1
        p_tooling_capa = tooling_num * TOOLING_CAPA
        
    plant_alloc = PLANT_COST / plant_dep_qty # calc allocated cost of plant building cost
    line_alloc = line_num * LINE_COST / x / LINE_DEP_YEAR # calc allocated cost of line cost
    tooling_alloc = tooling_num * TOOLING_COST / x / TOOLING_DEP_YEAR # calc allocated cost of tooling cost
    all_alloc = plant_alloc + line_alloc + tooling_alloc
    if line_num > PLANNED_NUM_OF_LINE: # if line_num is over planned num of line, cause error.
        print('Error: line_num is over PLANNED_NUM_OF_LINE.')
        break
    Y.append(all_alloc)
    
# show the precondition of this simulation
precondition_dict = {}
precondition_dict['plant_building_cost [Factory building cost]'] = f'{PLANT_COST:,}'
precondition_dict['line_building_cost [Line laying cost]'] = f'{LINE_COST:,}'
precondition_dict['tooling_cost [Mold cost]'] = f'{TOOLING_COST:,}'
precondition_dict['max_line_num_per_a_plant [Maximum number of line layout design strokes per factory(pcs/day)]'] = PLANNED_NUM_OF_LINE
precondition_dict['max_production_daily_capa [Line production capacity per day(pcs/day)]'] = LINE_DAILY_CAPA
precondition_dict['max_tooling_daily_capa [Mold production capacity per day]'] = TOOLING_DAILY_CAPA
precondition_dict['plant_depreciation_year [Number of years for depreciation of factory building]'] = PLANT_DEP_YEAR
precondition_dict['line_depreciation_year [Line depreciation set years]'] = LINE_DEP_YEAR
precondition_dict['tooling_depreciation_year [Depreciation setting years of mold]'] = TOOLING_DEP_YEAR
precondition_dict['max_line_num [Maximum number of lines laid]'] = line_num
precondition_dict['max_tooling_num [Maximum number of molds]'] = tooling_num
precondition_dict['plant_production_capa [Factory production capacity(pcs/yr)]'] = f'{END_QTY:,}'
df = pd.DataFrame(precondition_dict.values(), index=precondition_dict.keys(), columns=['precondition [Prerequisites]'])
display(df)

# set your plan
yourX = 1_000_000 # set your sales plan [!]
yourY = 999_999_999
for x, y in zip(x_range, Y):
    if x > yourX:
        yourY = y
        break
        
# show simulation result
plt.rcParams["font.size"] = 15
fig, ax = plt.subplots(1, 1, facecolor='#F5FBFF', figsize=(15,10))
ax.xaxis.set_major_formatter(plt.FuncFormatter(lambda x, loc: f'{int(x):,}'))
ax.yaxis.set_major_formatter(plt.FuncFormatter(lambda x, loc: f'{int(x):,}'))
ax.plot(x_range, Y, c='green')
ax.vlines(x=yourX, ymin=min(Y), ymax=max(Y), color='red')
ax.text(x=yourX*1.03, y=max(Y)*0.995, s=f'{yourY:,.2f} @ ( line_num:{np.ceil(yourX/LINE_CAPA):.0f}, tooling_num:{np.ceil(yourX/TOOLING_CAPA):.0f} )', color='red', fontsize=20)
fig.savefig('./data/img/FixedCostSim.png')
plt.show()

image.png

--When you google with Maxcy et al. [1965] silver stone, Financial Strategy of Automobile Manufacturers-Using Toyota as Material- I was caught. Interesting. ――In 1965, of course, there was no EXCEL. Mr. Maxy probably plotted by hand. I'm really grateful that python can draw so easily.

2. Banana smashing visualization

banana_sim


import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

def make_and_plot_data(p1, p2, b):
    X = np.arange(p1, p2, 1)
    Y = []
    for x in X:
        Y.append(b)
    ax.plot(X,Y,c='green')

X0 = 0
X1 = 50  # [!]
X2 = 100 # [!]
X3 = 200 # [!]

C0 = 2000 #Purchase amount X0 or more, selling price less than X1[!]
C1 = 1000 #Purchase amount X1 or more, selling price less than X2[!]
C2 = 500 #Purchase amount X2 or more, selling price less than X3[!]

yourX = 120 # [!]
yourY = 500 # [!]

plt.rcParams["font.size"] = 15
fig = plt.figure(facecolor='#F5FBFF', figsize=(15,10))
ax = fig.subplots(1,1)
make_and_plot_data(X0, X1, C0)
make_and_plot_data(X1, X2, C1)
make_and_plot_data(X2, X3, C2)
ax.xaxis.set_major_formatter(plt.FuncFormatter(lambda x, loc: f'{int(x):,}'))
ax.yaxis.set_major_formatter(plt.FuncFormatter(lambda x, loc: f'{int(x):,}'))
ax.vlines(x=yourX, ymin=0, ymax=C0, color='red')
ax.text(x=yourX*1.03, y=yourY*1.1, s=f'{yourY} @ {yourX:,}', color='red', fontsize=20)
fig.savefig('./data/img/bananaCostSim.png')
plt.show()

image.png

Recommended Posts

Drawing a silverstone curve using python
I tried drawing a pseudo fractal figure using Python
Derivatives learned using Python-(2) Draw a yield curve (JPYLibor curve)-
I made a Line-bot using Python!
Create a python GUI using tkinter
Try drawing a simple animation in Python
[Python] Drawing a swirl pattern with turtle
I tried drawing a line using turtle
[Python] Create a Batch environment using AWS-CDK
Scraping a website using JavaScript in Python
[Python] Scraping a table using Beautiful Soup
Draw a tree in Python 3 using graphviz
A program that plays rock-paper-scissors using Python
Try drawing a map with python + cartopy 0.18.0
[python] Streamline drawing
Start using Python
Scraping using Python
Create a GIF file using Pillow in Python
[Python] Split a large Flask file using Blueprint
Try to draw a life curve with python
Create a web map using Python and GDAL
View drug reviews using a list in Python
I tried reading a CSV file using Python
Run a Python file from html using Django
Create a Mac app using py2app and Python3! !!
Create a MIDI file in Python using pretty_midi
Let's make a module for Python using SWIG
Run a python script from excel (using xlwings)
[Python] Implementation of clustering using a mixed Gaussian model
[Python] Take a screenshot
Operate Redmine using Python Redmine
How to set up a Python environment using pyenv
Fibonacci sequence using Python
Try creating a compressed file using Python and zlib
Create a Python module
I made a login / logout process using Python Bottle.
Cut a part of the string using a Python slice
Data analysis using Python 0
A python lambda expression ...
(Python) Try to develop a web application using Django
Try drawing a social graph using Twitter API v2
[CRUD] [Django] Create a CRUD site using the Python framework Django ~ 1 ~
Graph drawing using matplotlib
Graph drawing in python
Until drawing a 3D graph in Python on windows10
[Python] Create a ValueObject with a complete constructor using dataclasses
Approximate a Bezier curve through a specified point using the least squares method in Python
Data cleaning using Python
Daemonize a Python process
Using Python #external packages
Register a ticket with redmine API using python requests
Implementing a generator using Python> link> yield and next ()> yield
Build a Python virtual environment using venv (Django + MySQL ①)
How to make a Python package using VS Code
WiringPi-SPI communication using Python
Build a Python environment on your Mac using pyenv
Age calculation using python
[Python] I tried running a local server using flask
[CRUD] [Django] Create a CRUD site using the Python framework Django ~ 2 ~
Build a Python development environment using pyenv on MacOS
Drawing with Python Tinker