Nothing is interesting if you're not interested
Helen Clark MacInnes
Python Stuff
I tend to spend too much time mucking around with Python code - as you can see from the bits of code scattered around this site. So, I've decided to add a page specifically for stuff related to just Python. It'll include snippets of code, interesting applications, algorithms or anything else Python related. Code that is purely there as a means to demonstrate or calculate something specific will remain as it is, in the most relevant post. Most of this stuff will be migrating to my sister pages -
- in the near future.
Sorry if you were hoping to see something on the Pythonidae family of snakes - interesting as they are.
Recently I installed Python 3.8 and subsequently had some difficulty installing the scientific packages I needed (SciPy, Pandas, Matplotlib etc.). Poked around and found a really excellent source of up-to-date Windows binary files of many open-source scientific packages. Here's the nitty-gritty info.
Incremental row,column indices
Recently, I was looking at how best to produce multiple sub-plots using Matplotlib in Python. Not particularly hard, although I was interested in using these with common x and y labels - I might include a further post outlining how this can be done. But, how do you allocate the appropriate data plot to the subplot itself - within a loop. I wanted a more Pythonic solution that just nested row,/column loops.
Matplotlib - subplots
As part of the work I do for the OU as an AL and also as bait of a consultant on developing Python content (sounds grander than it is), I wanted to get into the intricacies of using Matplotlib to produce acceptable sub-plots for scientific reports. Here's my attempt which covers using common x axis labels, overall x and y axis label text and 2 or more column plots. It deals with plot numbers that don't 'fill up' a nice rectangle.
Remove a spectrum's complex baseline.
Here's an interesting little function I cooked up. With many experimental spectra, there is an underlying 'background' signal that distorts the actual useful signal. Sometimes you can remove this by taking background spectra from somewhere where the actual signal is absent and subtract this (usually an average of several of them) from the useful spectrum.
In some cases, this isn't available, but the background is easy to simulate as, for example, it may be a straight line 'slope'. hence a simple function can be 'fitted' and subtracted.
However, there are clearly some cases where neither of these methodologies are possible. This post gives a simple function that I thought up and have used successfully.
In some cases, this isn't available, but the background is easy to simulate as, for example, it may be a straight line 'slope'. hence a simple function can be 'fitted' and subtracted.
However, there are clearly some cases where neither of these methodologies are possible. This post gives a simple function that I thought up and have used successfully.
Python code behind the COVID-19 page
Here is the Python I've used to generate the plots used on the COVID-19 pages (well it will be in time)
Tips for using Pandas
As part of a series, I thought it would be good to do some slightly advanced or more obscure tips and tricks for Python. Here I'm looking at Pandas.