Make XKCD-Style Plots From Python

[Randall Munroe] certainly understands the power of graphical representation of data. The humorous plots in his xkcd webcomic are one of the favorite parts for many readers. Their distinctive, Tufteian style delivers the information – in this case, a punch line – without excessive decoration. To be honest, we can’t get enough of them. A recent reddit thread reminded us that you can generate a similar look for your own data (humorous or otherwise) in Python using Matplotlib.

If you already have a plot generated with Matplotlib, activating xkcd-mode is as simple as calling a method on the pyplot object:

matplotlib.pyplot.xkcd()

The documentation recommends that you install the “Humor Sans” font for best effect. On one of our linux boxes, we were able to do this with a simple:

sudo apt-get install fonts-humor-sans

There will undoubtedly be similar incantations for other operating systems. It’s really that simple. In fact, the featured image above was generated with this minimal script:

#!/usr/bin/env python3

import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(0, 1, 100)
y = (x > 0.5) * (x - 0.5)

plt.xkcd(scale=5, length=400)
plt.xticks([])
plt.yticks([])
plt.ylabel('Downloads of "humor sans" font')
plt.text(0, 0.25, 'Article on xkcd() published')
plt.plot(x, y)
plt.plot([0.3, 0.475], [0.2, 0.025], 'black')
plt.gca().set_aspect(2*9/16)
plt.savefig('xkcd_plot.png', dpi=300)

Beyond generating humorous graphs for those with little artistic talent, these plots can also be used instead of hand-drawn sketches to indicate a simple model or expected result. The comic look of the plots conveys the idea that they don’t represent actual data, perhaps only a concept. We saw this done at one of the talks at the Hackaday SuperConference 2018.

We’ve also covered some of the xkcd comics before, such as when they subtly dissed Arduino back in 2010, before that was cool.

Spanning The Tree : Dr Radia Perlman & Untangling Networks

As computer networks get bigger, it becomes increasingly hard to keep track of the flow of data over this network. How do you route data, making sure that the data is spread to all parts of the network? You use an algorithm called the spanning tree protocol — just one of the contributions to computer science of a remarkable engineer, Dr. Radia Perlman. But before she created this fundamental Internet protocol, she also worked on LOGO, the first programming language for children, creating a dialect for toddlers.

Continue reading “Spanning The Tree : Dr Radia Perlman & Untangling Networks”

Digitize Your Graphs With WebPlotDigitizer

Have you ever had to write a bit of code to interpret a non-linear analog reading as picked up by an ADC? When all you have to work with for your transfer function is a graph in a semiconductor datasheet that was probably written thirty years ago and prints out the size of a postage stamp, that’s a rather annoying task. Wouldn’t it be nice if you had access to the numbers behind the graph!

You can’t knock on the office door of the engineer who created it back in the ’80s, he’s probably  in retirement and playing golf or growing prize petunias by now. But you can digitize the graph to get yourself a lot closer to the action, and to help you in your quest there’s a handy online tool.

2N3904-current-gain
2N3904 current gain

WebPlotDigitizer is not new, it’s been around for quite a few years now. But it’s still worth talking about, because it’s one of those tools to keep in reserve. If you’ve ever needed it, you’ll know what we mean.

So how does it work? Load an image with a graph in it, select some points on the X and Y axis, roughly trace the curve with a marker tool, and set it in motion. Let’s give it a go. We’re going to try digitizing the current gain plot from the 2N3904 datasheet (PDF) that we examined a few days ago.

data-points
Data points!

So, open the WebPlotDigitizer app, load the graph image captured from the sheet as a JPEG. It asks what type of graph you’ve loaded, in this case a 2D X-Y plot. It asks you to identify four known points on the axes and supply their values. You also tell it if the axes are logarithmic at this point. Select “Automatic mode” on the right hand side, then click “Pen” and mark the graph trace, then select the colour of the trace. Click the “Run” button, and your data points appear. Hit the “View data” button, and there you have it. A few rogue points to remove perhaps, but it does a pretty good job.

If WebPlotDigitizer has engaged your interest, you’ll be pleased to know that it’s open-source, and you can find all its code on GitHub. There is also a handy video tutorial which you can see below the break. Continue reading “Digitize Your Graphs With WebPlotDigitizer”

Arduino Data Logger Maps Out The Potholes On Your Morning Commute

Now you can prove that you have the bumpiest commute in the office by measuring how rough your ride actually is. [Techbitar] calls the project the Bump-O-Meter. It uses an Arduino, GPS, and accelerometer to map out rough roads.

The hardware was built on a breadboard and [Techbitar] goes into detail about connecting and communicating with each module used. Once it’s running, the logger will read up to six sensors and record them to an SD card. In the video after the break he shows the method used to dump and graph the data. He starts by looking at the data in a spreadsheet. There are many fields included in the file but only three of them are needed to graph what is seen above. After narrowing down the number of columns he heads over to GPS Visualizer and uploads the data set which is then automatically plotted on the map.

In a Utopian society all city owned vehicles would have a system like this and the bad sections of road would automatically appear on the road crew’s repair list.

Continue reading “Arduino Data Logger Maps Out The Potholes On Your Morning Commute”

Multi-channel Analog Input Module Is A Good Jumping-off Point For Many Projects

[Scott Harden] has already produced some projects which measure analog inputs. But he’s got plans for more and wanted a base system for graphing analog signals. You can see the small board next to his laptop which offers the ability to sample up to six signals and push them to a PC via USB.

The ATmega48 and a few supporting components are all you’ll find on that board. The USB connection is taken care of by an FTDI cable. He went that route because the cables are relatively cheap, easy to come by, and already have driver support on all the major operating systems. If you look at the screen you can see a window graphing one analog input in real-time. He wrote this in Python (which is once again a cross-platform tool) and it has no problem graphing all six inputs at once.

This is immediately useful as an upgrade to [Scott’s] ECG machine. His future plans include a Pulse Oximeter, EEG, and EEG.

Analog Test Interface For Your Computer

Wanting to test the response curves on some analog parts, [Don Sauer] devised a way of using simple tools to graph analog tests on a computer. Here you can see the results of testing NPN, PNP, NMOS and PMOS transistors, but modifying the input circuitry would let you test just about anything you want.

[Don] is using an Arduino as the hardware interface. He needed some additional parts, like an op-amp and some passives. Instead of building this on a breadboard, he printed the circuit out on a piece of cardboard, hot glued the components in place, then wired them up. This will let him reuse the interface in the future, but is quicker than designing and etching a PCB.

He uses a Processing sketch to capture the test data streaming in from the Arduino. Once recorded, he uses SciLab to create the graphs. He also covers a method of sifting through the data using Octave, another open source program that feels somewhat like MATLAB.

Lucid Dreaming

When we saw [merkz] use of an Arduino to produce lucid dreaming we were quite shocked. Unlike typical setups that just flash a light through sleep, his system monitors eye movement through electrodes and is able to send the data to a computer for graphing and analyzing.  The only problem being we couldn’t find a circuit diagram or code.

Not ones to be shot down so quickly, a Google revealed this thread on making ‘Dream Goggles’, which was really a Brain-Wave Machine based on the parallel port. Some modifications of an ECG collector’s electrodes using sound cards, and you could have your own lucid dreaming.

[Thanks Phil]