After tentatively completing the draft of the previous post, I decided to look at what fill_betweenx() might look like. While doing so, I realized I had another variable I could play with.

Note: Renamed btw_x_apart() to btw_n_apart() when I started looking at fill_betweenx(). Didn’t want to confuse things if I created new functions or refactored the existing functions to use either fill_between() or fill_betweenx().

The plotting line in the loop for the function btw_n_apart() looks like this:

  for i in b_rng:
    if i == i+dx:
      continue
    axt.fill_between(r_xs[i], r_ys[i], r_ys[i+dx], alpha=alph, color=cycle[c_ndx])
    ......

It’s the dx that changes the image look. Something similar goes on in btw_rnd(). Except in the latter, there are times the deciding value, b_rw, is randomly generated within the function.

In each iteration of the loop, not only are differing rows selected from the y data but also from the x data. What if I fixed the x row, while shifting the y rows.

You are likely thinking this is becoming a nightmare—getting totally out-of-hand. You are probably right. But, I just feel like I want to have a look at how this might affect the images. So, another comparison plot or three.

Code Refactor

Let’s take a look at fixing the data row not being used to determine where the colours are placed when plotting between rows on the other axis. I am not sure that this will have a big effect. But it’s probably something at which we should have, at least, a quick look. I initially started out by writing a plot to generate variations on four sub-images on a single plot. But, I found things were a bit too small.

I had for sometime been a little aggravated at having to cycle through the variations in plot type 27, to get a chance to see the same one again. So, I refactored the plot code to get user input to determine what functions/values to use to generate the output image. I won’t go in the code details, pretty basic use of Python’s input function. And, the code is somewhat lengthy, repetitive and boring.

But the questions I ask are:

  • Which plot function (1-btw_rand, 2-btw_n_apart, 3-random, default 1):
  • Which axis to plot between, x or y or r(andom); default y:
  • Plot in reverse order, y or n; default n:
  • Fix non-colouring axis, n or row #; default n:
  • If btw_rand selected:
    • Which line, s(tart), e(nd), m(iddle), r(andom); default e:
  • If btw_n_apart:
    • How many lines between, 1, 2, … or 0 for random; default 1:
    • Should lines overlap, y or n; default y:

If I just hit Enter the default is used. Otherwise the value entered, if valid, becomes the new default. I am thinking about asking for an alpha value. But that will also require refactoring the four colour between functions. So have not yet done so. For now, I am generating the images with alpha=1.

Fix Non-Colouring Axis

Okay, now let’s have a look at the consequences of fixing the non-colouring axis. For fill_between that would be the x axis. For fill_betweenx the y axis.

I won’t bother with any code. If the fix input request gets a row number, the call to the appropriate function passes that row number (converted to an integer) to the function via the fix= parameter.

Example 1

This first set uses a curve based on 7 ellipse shaped wheels. They all use the btw_n_apart() funtion. Colouring between the y axis data rows.

I had planned to do more of them using this curve, but a bug got in the way.

Between each line with overlap, plotted in datalist order, no fixed x data row
gnarly spirograph images generated with matplotlib fill_between(), with variations between which rows the colouring occurs
Between each line with overlap, plotted in datalist order, fixed at x[2]
gnarly spirograph images generated with matplotlib fill_between(), with variations between which rows the colouring occurs
Between each line with overlap, plotted in datalist order, fixed at x[4]
gnarly spirograph images generated with matplotlib fill_between(), with variations between which rows the colouring occurs

The coloured spaces definitely seem to be larger/thicker. Which to me, in many cases, enhances the image.

Example 2

This set of images uses a curve based on 7 tetracuspid shaped wheels. All but the last use the btw_n_apart() funtion. The last uses the btw_rand() function.

Between each line in x dataset with overlap, in datalist order, fixed at y[2]
gnarly spirograph images generated with matplotlib fill_between(), with variations between which rows the colouring occurs
Between every 2nd line in x dataset with overlap, in datalist order, fixed at y[2]
gnarly spirograph images generated with matplotlib fill_between(), with variations between which rows the colouring occurs
Between every 3rd line in x dataset with overlap, in datalist order, fixed at y[2]
gnarly spirograph images generated with matplotlib fill_between(), with variations between which rows the colouring occurs
Between middle line on y-axis, datalist order, fixed at x[5]
gnarly spirograph images generated with matplotlib fill_between(), with variations between which rows the colouring occurs

I do find these paint between images interesting. But not really sure that fixing the non-colouring axis to a single row makes a lot of difference from the non-fixed case. And, in some cases definitely worse. E.G. the last one above. And a minor change in any one variable makes for seriously subtle differences.

So enough of that.

fill_between vs fill_betweenx

You’ve seen use of fill_betweenx above, but I thought I’d see if I could get a better comparison for you.

As mentioned, rather than add a parameter to my two base functions, I just copied and modified them to get two new functions for colouring in the x direction rather than the y direction.

And again, I am not going to bother with the code. I am not sure how much difference using one over the other will generate in the images. But let’s find out.

Example 1

These two images use the btw_rand set of functions. The curve is based on 9 circle shaped wheels. For both the fixed line is the last row of the colour-between axis dataset. And the betweens are plotted in dataset order.

Colour between y-axis
gnarly spirograph images generated with matplotlib fill_between(), with variations between which rows the colouring occurs
Colour between x-axis
gnarly spirograph images generated with matplotlib fill_between(), with variations between which rows the colouring occurs

You can certainly see the change in the axis being used to colour between the data rows.

Example 2

The following two images use the btw_n_apart set of functions. The curve is based on 7 rhombus shaped wheels. Colours between every line with overlap in the dataset order. But, I did modify the two function versions to not plot between rows 0 and 1. That always seemed to add a big blob to the images.

Colour between y-axis
gnarly spirograph images generated with matplotlib fill_between(), with variations between which rows the colouring occurs
Colour between x-axis
gnarly spirograph images generated with matplotlib fill_between(), with variations between which rows the colouring occurs

Was going to use the same curve to look at differing line separations. But another bug put an end to that idea. Will see what I manage over the next day or two. Time to quit for today.

And, it looks to me that there is definitely a difference. In some cases more subtle than in others. But, still a viable option for generating images.

That’s It for Now

Was going to look at some more comparisons but decided to call it on this one. Markdown file is 11 KB and there are 1.6 MB of images for this post. Seems plenty big enough to me. So, another post or two. Likely not a lot of code, mostly comparing images based on the variations I’ve been playing with. And, perhaps, a new one that came to mind last night (i.e. the night before completing the draft for this post, not its publish date).

The more I play with these images, the more I wish I had the skill to create an app of some sort. But no real idea how to create apps. And most certainly, don’t know how one could do that with Python. I currenly am not interested in trying to learn Apple’s and/or Google’s phone app languages. Did more or less complete a course on Javascript web apps, but never really got into that whole eco-system.

Until next time, enjoy your time at the keyboard. May you find it as peaceful as do I.

Resources