Adding a colormap to a figure without imshow/countour set

Posted on 25 March 2015 in matplotlib • Tagged with python, matplotlib

Example: plot a packing using circles, and use the foreground color to show some value for each particle, for example the contact number Z:

The trick to this is to call plt.scatter() to plot a single point outside the axis range. This allows plt.colorbar() to find cmap and …

Continue reading

raw_input in matplotlib with plot interaction

Posted on 08 August 2012 in misc • Tagged with python, matplotlib

When working with data, you sometimes need to view the data and give input on how to continue. However, a simple

answer = raw_input()
will not work: the plot GUI will block while the raw_input() is waiting. The following is a (admittedly hacky) solution to this problem: run raw_input() in a seperate thread, and poll the GUI using waitforbuttonpress():

Continue reading