Quick’n’Dirty plotting with Python
Tags: Python, Visualization, Matplotlib, Data Science, Efficiency

Photo (background) by Mitchell Luo on Unsplash

What is one of the most common excuses for using Excel: “It’s good for a quick’n’dirty plot”. If you’re satisfied with Excel for visualizing data, then that’s fine. However, this article is about a quicker and dirtier method for plotting data in Python :)

The simple code for plotting x vs y data is as follows:

The data file in this snippet is a two column text file.

This is relatively simple: we import the relevant modules, load the data and plot it. The number of lines of code grows when we do custom detailing. But that doesn’t matter right now as this is about the quick’n’dirty! Although the above code isn’t complex, many people would find typing this out each time to be a pain.

Two things you could do to save time and effort in the future:

Keep a copy of this .py file somewhere special and copy it across each time you need it, that way you only need to change the file name.

Make your own plotting library, so that you have plotting functions for particular data files. This will take some time and experience to build up, but will make things more efficient in the long run.

The 2nd of these two methods is better for quick’n’dirty plotting, but some of you would still find it annoying to type anything for every new plot. However, there is another method, which requires the following steps (on a Windows machine):

Create a python file containing the following code and save it anywhere you like (but preferably somewhere easy to remember).

Spot the difference from the previous code

Create a .cmd file in the same folder that contains the following code. Make sure to edit the path (in orange) to the path of your python file from step 1.

Create a shortcut of this .cmd file. Right-click on the shortcut, select properties and choose Minimized in the Run option (This minimizes the terminal each time it is run).

Open a File Explorer window and type “shell:sendto” or just “sendto”. Copy across the shortcut of the .cmd file to the ‘SendTo’ folder.

All done! Now when you right-click on a data file you can hover the mouse over ‘Send to’ in the context menu and click on the .cmd file. In this example, the data file is ONLY two columns of x,y data. You may need to make some adjustments for ignoring text, such as the skiprows parameter.

You now have an excellent quick’n’dirty way to visualize data. Plotting it using matplotlib allows you to zoom-in on specific regions for inspection and you can quickly save a decent looking plot for sharing. You can edit your code for plotting multiple files by doing a simple ‘for loop’. From here, you can get fancy and plot multiple axes with a legend to keep track of which files you have opened.

You can make further adjustments to your code for your specific data file formats. The Pandas library is great for loading and examining .csv files. You can also make a few different options in your ‘SendTo’ folder for different file types or plotting methods.

Now, at this point you might be thinking that we’re getting past the quick’n’dirty and into the slow’n’clean… But you need to remember that you only need to create each of these codes once. After this it’s all point’n’click! Tools like this might take a bit of time to make at first, but they’ll save you a lot time in the long run and make visualsing data much easier and more flexible. Enjoy!