bb-3rd-time-thru.html
001|
002| from os import path
003| from math import sqrt, pi,tau, sin,cos, radians
004| import matplotlib.pyplot as plt
005| from matplotlib.ticker import NullLocator, MultipleLocator, NullFormatter, FormatStrFormatter
006| from matplotlib.ticker import FixedLocator, FixedFormatter
007|
008| BasePath = r'C:\CJS\prj\Python\charts'
009| ImgsPath = path.join(BasePath,'img')
010| Filename = 'bb-3rd-thru-order.png'
011|
012| years = [1912, 1916, 1927, 1932, 1955, 1970, 1998, 2024]
013| stats = {
014| 1912: [[0.693, 0.678, 0.688, 0.706], [0.706, 0.675, 0.731, None]],
015| 1916: [[0.629, 0.623, 0.639, 0.650], [0.639, 0.618, 0.707, None]],
016| 1927: [[0.697, 0.731, 0.734, 0.752], [0.745, 0.750, 0.844, None]],
017| 1932: [[0.716, 0.736, 0.734, 0.748], [0.758, 0.755, 0.746, None]],
018| 1955: [[0.692, 0.734, 0.744, 0.751], [0.724, 0.753, 0.689, None]],
019| 1970: [[0.675, 0.697, 0.742, 0.775], [0.710, 0.745, 0.760, None]],
020| 1998: [[0.725, 0.768, 0.807, 0.786], [0.732, 0.783, 0.562, None]],
021| 2024: [[0.696, 0.727, 0.761, 0.717], [0.693, 0.767, 0.875, None]],
022| }
023|
024| xs = [1, 2, 3, 4]
025|
026| ys2024sp = stats[2024][0]
027| ys2024rp = stats[2024][1]
028|
029| ys1998sp = stats[1998][0]
030| ys1998rp = stats[1998][1]
031|
032| ys1970sp = stats[1970][0]
033| ys1970rp = stats[1970][1]
034|
035| ys1955sp = stats[1955][0]
036| ys1955rp = stats[1955][1]
037|
038| ys1932sp = stats[1932][0]
039| ys1932rp = stats[1932][1]
040|
041| ys1927sp = stats[1927][0]
042| ys1927rp = stats[1927][1]
043|
044| ys1916sp = stats[1916][0]
045| ys1916rp = stats[1916][1]
046|
047| ys1912sp = stats[1912][0]
048| ys1912rp = stats[1912][1]
049|
050| xmin,xmax = 0.75, 4.25
051| ymin,ymax = +0.500, +0.900
052|
053| xlabels = ["1st", "2nd", "3rd", "4th"]
054|
055|
056| fig, axes = plt.subplots(nrows=2, ncols=4, squeeze=True)
057| fig.suptitle('MLB Times Through the Order', fontsize=20, fontweight='bold')
058| ax1 = axes[0][0]
059| ax2 = axes[0][1]
060| ax3 = axes[0][2]
061| ax4 = axes[0][3]
062| ax5 = axes[1][0]
063| ax6 = axes[1][1]
064| ax7 = axes[1][2]
065| ax8 = axes[1][3]
066|
067|
068| ax1.set_title('2024', fontweight='bold')
069| ax1.set_xlim(xmin,xmax)
070| ax1.xaxis.set_major_locator(FixedLocator([1,2,3,4]))
071| ax1.xaxis.set_major_formatter(FixedFormatter(xlabels))
072| ax1.xaxis.set_minor_locator(NullLocator())
073| ax1.xaxis.set_minor_formatter(NullFormatter())
074|
075| ax1.set_ylabel('OPS', fontsize=16, fontweight='bold')
076| ax1.set_ylim(ymin,ymax)
077| ax1.yaxis.set_major_locator(MultipleLocator(0.100))
078| ax1.yaxis.set_major_formatter(FormatStrFormatter('%+.3f'))
079| ax1.yaxis.set_minor_locator(MultipleLocator(0.025))
080| ax1.yaxis.set_minor_formatter(NullFormatter())
081|
082| ax1.grid(which='major', axis='both', color='#7f7f7f', lw=1.2,ls='-',zorder=1, alpha=1.0)
083| ax1.grid(which='minor', axis='both', color='#bfbfbf', lw=0.6,ls='-',zorder=0, alpha=1.0)
084| ax1.tick_params(which='major', axis='both', direction='out', color='#000000')
085| ax1.tick_params(which='minor', axis='both', direction='out', color='#000000')
086|
087| line1, = ax1.plot(xs,ys2024sp, c='#ff0000', lw=3.0, alpha=0.80, zorder=12)
088| line2, = ax1.plot(xs,ys2024rp, c='#0000ff', lw=3.0, alpha=0.80, zorder=11)
089|
090|
091| ax2.set_title('1998', fontweight='bold')
092| ax2.set_xlim(xmin,xmax)
093| ax2.xaxis.set_major_locator(FixedLocator([1,2,3,4]))
094| ax2.xaxis.set_major_formatter(FixedFormatter(xlabels))
095| ax2.xaxis.set_minor_locator(NullLocator())
096| ax2.xaxis.set_minor_formatter(NullFormatter())
097|
098| ax2.set_ylim(ymin,ymax)
099| ax2.yaxis.set_major_locator(MultipleLocator(0.100))
100| ax2.yaxis.set_major_formatter(NullFormatter())
101| ax2.yaxis.set_minor_locator(MultipleLocator(0.025))
102| ax2.yaxis.set_minor_formatter(NullFormatter())
103|
104| ax2.grid(which='major', axis='both', color='#7f7f7f', lw=1.2,ls='-',zorder=1, alpha=1.0)
105| ax2.grid(which='minor', axis='both', color='#bfbfbf', lw=0.6,ls='-',zorder=0, alpha=1.0)
106| ax2.tick_params(which='major', axis='both', direction='out', color='#000000')
107| ax2.tick_params(which='minor', axis='both', direction='out', color='#000000')
108|
109| ax2.plot(xs,ys1998sp, c='#ff0000', lw=3.0, alpha=0.80, zorder=12)
110| ax2.plot(xs,ys1998rp, c='#0000ff', lw=3.0, alpha=0.80, zorder=11)
111|
112|
113| ax3.set_title('1970', fontweight='bold')
114| ax3.set_xlim(xmin,xmax)
115| ax3.xaxis.set_major_locator(FixedLocator([1,2,3,4]))
116| ax3.xaxis.set_major_formatter(FixedFormatter(xlabels))
117| ax3.xaxis.set_minor_locator(NullLocator())
118| ax3.xaxis.set_minor_formatter(NullFormatter())
119|
120| ax3.set_ylim(ymin,ymax)
121| ax3.yaxis.set_major_locator(MultipleLocator(0.100))
122| ax3.yaxis.set_major_formatter(NullFormatter())
123| ax3.yaxis.set_minor_locator(MultipleLocator(0.025))
124| ax3.yaxis.set_minor_formatter(NullFormatter())
125|
126| ax3.grid(which='major', axis='both', color='#7f7f7f', lw=1.2,ls='-',zorder=1, alpha=1.0)
127| ax3.grid(which='minor', axis='both', color='#bfbfbf', lw=0.6,ls='-',zorder=0, alpha=1.0)
128| ax3.tick_params(which='major', axis='both', direction='out', color='#000000')
129| ax3.tick_params(which='minor', axis='both', direction='out', color='#000000')
130|
131| ax3.plot(xs,ys1970sp, c='#ff0000', lw=3.0, alpha=0.80, zorder=12)
132| ax3.plot(xs,ys1970rp, c='#0000ff', lw=3.0, alpha=0.80, zorder=11)
133|
134|
135| ax4.set_title('1955', fontweight='bold')
136| ax4.set_xlim(xmin,xmax)
137| ax4.xaxis.set_major_locator(FixedLocator([1,2,3,4]))
138| ax4.xaxis.set_major_formatter(FixedFormatter(xlabels))
139| ax4.xaxis.set_minor_locator(NullLocator())
140| ax4.xaxis.set_minor_formatter(NullFormatter())
141|
142| ax4.set_ylim(ymin,ymax)
143| ax4.yaxis.set_major_locator(MultipleLocator(0.100))
144| ax4.yaxis.set_major_formatter(NullFormatter())
145| ax4.yaxis.set_minor_locator(MultipleLocator(0.025))
146| ax4.yaxis.set_minor_formatter(NullFormatter())
147|
148| ax4.grid(which='major', axis='both', color='#7f7f7f', lw=1.2,ls='-',zorder=1, alpha=1.0)
149| ax4.grid(which='minor', axis='both', color='#bfbfbf', lw=0.6,ls='-',zorder=0, alpha=1.0)
150| ax4.tick_params(which='major', axis='both', direction='out', color='#000000')
151| ax4.tick_params(which='minor', axis='both', direction='out', color='#000000')
152|
153| ax4.plot(xs,ys1955sp, c='#ff0000', lw=3.0, alpha=0.80, zorder=12)
154| ax4.plot(xs,ys1955rp, c='#0000ff', lw=3.0, alpha=0.80, zorder=11)
155|
156|
157| ax5.set_title('1932', fontweight='bold')
158| ax5.set_xlim(xmin,xmax)
159| ax5.xaxis.set_major_locator(FixedLocator([1,2,3,4]))
160| ax5.xaxis.set_major_formatter(FixedFormatter(xlabels))
161| ax5.xaxis.set_minor_locator(NullLocator())
162| ax5.xaxis.set_minor_formatter(NullFormatter())
163|
164| ax5.set_ylabel('OPS', fontsize=16, fontweight='bold')
165| ax5.set_ylim(ymin,ymax)
166| ax5.yaxis.set_major_locator(MultipleLocator(0.100))
167| ax5.yaxis.set_major_formatter(FormatStrFormatter('%+.3f'))
168| ax5.yaxis.set_minor_locator(MultipleLocator(0.025))
169| ax5.yaxis.set_minor_formatter(NullFormatter())
170|
171| ax5.grid(which='major', axis='both', color='#7f7f7f', lw=1.2,ls='-',zorder=1, alpha=1.0)
172| ax5.grid(which='minor', axis='both', color='#bfbfbf', lw=0.6,ls='-',zorder=0, alpha=1.0)
173| ax5.tick_params(which='major', axis='both', direction='out', color='#000000')
174| ax5.tick_params(which='minor', axis='both', direction='out', color='#000000')
175|
176| ax5.plot(xs,ys1932sp, c='#ff0000', lw=3.0, alpha=0.80, zorder=12)
177| ax5.plot(xs,ys1932rp, c='#0000ff', lw=3.0, alpha=0.80, zorder=11)
178|
179|
180| ax6.set_title('1927', fontweight='bold')
181| ax6.set_xlim(xmin,xmax)
182| ax6.xaxis.set_major_locator(FixedLocator([1,2,3,4]))
183| ax6.xaxis.set_major_formatter(FixedFormatter(xlabels))
184| ax6.xaxis.set_minor_locator(NullLocator())
185| ax6.xaxis.set_minor_formatter(NullFormatter())
186|
187| ax6.set_ylim(ymin,ymax)
188| ax6.yaxis.set_major_locator(MultipleLocator(0.100))
189| ax6.yaxis.set_major_formatter(NullFormatter())
190| ax6.yaxis.set_minor_locator(MultipleLocator(0.025))
191| ax6.yaxis.set_minor_formatter(NullFormatter())
192|
193| ax6.grid(which='major', axis='both', color='#7f7f7f', lw=1.2,ls='-',zorder=1, alpha=1.0)
194| ax6.grid(which='minor', axis='both', color='#bfbfbf', lw=0.6,ls='-',zorder=0, alpha=1.0)
195| ax6.tick_params(which='major', axis='both', direction='out', color='#000000')
196| ax6.tick_params(which='minor', axis='both', direction='out', color='#000000')
197|
198| ax6.plot(xs,ys1927sp, c='#ff0000', lw=3.0, alpha=0.80, zorder=12)
199| ax6.plot(xs,ys1927rp, c='#0000ff', lw=3.0, alpha=0.80, zorder=11)
200|
201|
202| ax7.set_title('1916', fontweight='bold')
203| ax7.set_xlim(xmin,xmax)
204| ax7.xaxis.set_major_locator(FixedLocator([1,2,3,4]))
205| ax7.xaxis.set_major_formatter(FixedFormatter(xlabels))
206| ax7.xaxis.set_minor_locator(NullLocator())
207| ax7.xaxis.set_minor_formatter(NullFormatter())
208|
209| ax7.set_ylim(ymin,ymax)
210| ax7.yaxis.set_major_locator(MultipleLocator(0.100))
211| ax7.yaxis.set_major_formatter(NullFormatter())
212| ax7.yaxis.set_minor_locator(MultipleLocator(0.025))
213| ax7.yaxis.set_minor_formatter(NullFormatter())
214|
215| ax7.grid(which='major', axis='both', color='#7f7f7f', lw=1.2,ls='-',zorder=1, alpha=1.0)
216| ax7.grid(which='minor', axis='both', color='#bfbfbf', lw=0.6,ls='-',zorder=0, alpha=1.0)
217| ax7.tick_params(which='major', axis='both', direction='out', color='#000000')
218| ax7.tick_params(which='minor', axis='both', direction='out', color='#000000')
219|
220| ax7.plot(xs,ys1916sp, c='#ff0000', lw=3.0, alpha=0.80, zorder=12)
221| ax7.plot(xs,ys1916rp, c='#0000ff', lw=3.0, alpha=0.80, zorder=11)
222|
223|
224| ax8.set_title('1912', fontweight='bold')
225| ax8.set_xlim(xmin,xmax)
226| ax8.xaxis.set_major_locator(FixedLocator([1,2,3,4]))
227| ax8.xaxis.set_major_formatter(FixedFormatter(xlabels))
228| ax8.xaxis.set_minor_locator(NullLocator())
229| ax8.xaxis.set_minor_formatter(NullFormatter())
230|
231| ax8.set_ylim(ymin,ymax)
232| ax8.yaxis.set_major_locator(MultipleLocator(0.100))
233| ax8.yaxis.set_major_formatter(NullFormatter())
234| ax8.yaxis.set_minor_locator(MultipleLocator(0.025))
235| ax8.yaxis.set_minor_formatter(NullFormatter())
236|
237| ax8.grid(which='major', axis='both', color='#7f7f7f', lw=1.2,ls='-',zorder=1, alpha=1.0)
238| ax8.grid(which='minor', axis='both', color='#bfbfbf', lw=0.6,ls='-',zorder=0, alpha=1.0)
239| ax8.tick_params(which='major', axis='both', direction='out', color='#000000')
240| ax8.tick_params(which='minor', axis='both', direction='out', color='#000000')
241|
242| ax8.plot(xs,ys1912sp, c='#ff0000', lw=3.0, alpha=0.80, zorder=12)
243| ax8.plot(xs,ys1912rp, c='#0000ff', lw=3.0, alpha=0.80, zorder=11)
244|
245| fig.text(0.5, 0.02, 'Times thru the order', ha='center', fontsize=22, fontweight='bold')
246| fig.legend(handles=[line1, line2], labels=['Starting Pitcher', 'Relief Pitcher'], loc='lower right')
247|
248| fig.set_figwidth(12.0)
249| fig.set_figheight(8.0)
250| fig.subplots_adjust(left=0.083, right=0.99, bottom=0.11, top=0.91)
251|
252| fn = path.join(ImgsPath, Filename)
253| fig.savefig(fn)
254| print('wrote: %s' % fn)
255| print()
256|
257|
258|
259|
260| '''eof'''
261|