Making your plots zing.
Matplotlib allows you to control many aspect of your graphs. In this article we will see how to style line plots. This includes
You can choose to plot data points using lines, or markers, or both.
Matplotlib has a simple notation to set the colour, line style and marker style using a coded text string, for example ‘r:’ creates a red, dottedline. …
This article is a quick guide on how to create and run your own open-source project. Specifically, it assumes it will be a Python project, although many of the things covered here can be applied to other types of project.
This isn’t a guide on how to set up a GitHub account and commit your first source files. Instead, it focusses on the wider whys and hows of open source development, and will hopefully help you to avoid the common pitfalls.
People create open-source software for many different reasons.
Quite often, a developer will decide to create a piece of…
What I learned from writing three Python books in a year
Over the past year or so, I have written three e-books on various topics in Python programming. Although I certainly don’t consider myself to be an expert on self-publishing, I have learned a bit in this time, so I will share it here. I hope you might find it useful.
This article covers four stages:
I have found the whole process takes me about 3 months, if I put most of my hobby time…
Process images in 3 lines of Python
Pillow is a versatile and popular Python imaging library. The ImageEnhance module is a particularly useful module within Pillow. It can be used to adjust colour, contrast, brightness and sharpness in a few simple lines of code.
Each image enhance function is implemented as an object that implements the
_Enhance interface. The interface provides a single method:
For example, the
ImageEnhance.Brightness class controls the brightness of an image, It has an
enhance method that it inherits from
factor is a number that controls the effect. For example, for
Easy animation with generativepy
generativepy makes it very easy to create animated GIFs. This can be done with a simple script, and usually results in a fairly well optimised GIf file.
gif module makes use of the gifsicle application. This can be downloaded for free, and must be installed on your system in order for the
gif module to work.
GIF (Graphics Interchange Format) is a bitmap image format that was developed in the 1980s for transferring images over networks. …
Deriving new functions with functools
Functional programming is a paradigm in which functions form the fundamental building blocks.
It should be no surprise that functional programming includes several techniques for deriving new functions from existing functions. This is analogous to object oriented programming, where classes are the building block, and we have various ways to derive new classes from existing ones (inheritance and composition, for example). In both cases, the aim is the same — to reuse existing code (following the DRY principle, don’t repeat yourself).
Partial application is one such technique.
Here is a function that returns the value…
It is, of course, vital to test software. There are various ways to test software, including:
Simple implementations of the List and Maybe monads.
In the article on the Failure monad we looked at a simple definition of what a monad is:
A monad is a design pattern that allows us to add a context to data values, and also allows us to easily compose existing functions so that they execute in a context aware manner.
In this article we will look at two other common monads:
A List monad allows us to process lists of values, without cluttering our code with looping constructs.
As with the Failure monad, our List monad…
A simple implementation of the Failure monad.
Image by Safijc
Monads have a reputation for being difficult to understand, but in this article we will look at a simple Python implementation of a simple monad. This will hopefully give some insight into what monads are all about.
In functional programming, we use functions as our primary building block, and function composition as one of the basic ways to structure our code. By function composition we mean functions that call other functions, like this:
y = str(neg(int(x)))
This composed function takes a string, converts it to an integer, negates it, and…
Converting individual markdown pages to html.
In a previous article we looked at what static sites are, and how they work.
Now we will look at how to convert a single markdown file into an HTML file.
This diagram from the previous article shows the basic process for converting a set of markdown files into the required HTML files for a complete website:
This time we will look in more detail at what is involved in converting a single page of markdown into the corresponding HTML file: