

You should be able to figure out what is going on without any intimate knowledge of Quartz. The code to generate the figure is fairly easy to read. You should end up with a PDF file called energylevels.pdf, containing a figure similar to the one shown above. To use this script, enter it in a file called EnergyLevels.py, make the file executable, and run it using the command. # Draw 5 random transitions for demonstration purposes

# Apply transform so that we can draw in the plot coordinatesĬ.scaleCTM(xPageRange/xPlotRange, yPageRange/yPlotRange) # Define the mapping between plot coordinatesĭef drawLevelTransition(c, firstLevel,secondLevel):Ĭ.selectFont ("Helvetica", 0.07, kCGEncodingMacRoman)Ĭ = CGPDFContextCreateWithFilename ("energylevels.pdf", pageRect) Only around 70 lines of Python code are required to produce this diagram.

It is loosely based on a molecular level diagram, but could easily originate from some other field. This figure could represent transitions between different states of a system. These wrappers make it surprisingly easy to automatically generate diagrams. And when you generate a PDF file from inside a Mac application, you are also benefitting directly from Quartz.Īpple have supplied Python wrappers for Quartz since the release of Panther. The eye candy you see whenever you turn on a Mac, from transparent windows to genie effects, is all due to the brilliance of Quartz. Quartz has been in Mac OS X since day one, and has played an important role in its success. Standard plotting and visualization packages are adequate for most researchers, most of the time, but what if you have to follow a path less travelled, and need diagrams that are not easily generated by existing software? With a little Python, you can relatively easily produce custom graphics by leveraging one of Mac OS X’s great technologies: Quartz.
