I am starting to render plots with matplotlib as I learn both python and this interesting plotting library. I need help with a custom plot for a problem I am working on. May be there is an inbuilt function already for this.
Problem:
I am trying to draw a table(rectangle) as a plot with 96 individual cells ( 8 rows X 12 cols). Color each alternative cell with a specific color ( like a chess board : instead of black/white I will use some other color combination) and insert value for each cell from a pandas data frame or python dictionary. Show the col and row labels on the side.
Sample Data: http://pastebin.com/N4A7gWuH
I would like the plot to look something like this substituting the values in the cells from a numpy/pandas ds.
Sample Plot: http://picpaste.com/sample-E0DZaoXk.png
Appreciate your input.
PS: did post the same on mathplotlib’s mailing list
Basically, you can just use
imshowormatshow.However, I’m not quite clear what you mean.
If you want a chessboard with every “white” cell colored by some other vector, you could do something like this:
Obviously, this only works for things with and odd number of rows and columns. You can iterate over each row for datasets with an even number of rows and columns.
E.g.:
However, the number of “data” cells in each row is going to be different, which is where I get confused by your problem definition.
By definition, a checkerboard pattern has a different number of “white” cells in each row.Your data presumably (?) has the same number of values in each row. You need to define what you want to do. You can either truncate the data, or add an extra column.
Edit: I just realized that that’s true only for odd-length numbers of columns.
Regardless, I’m still confused by your question.
Do you want have a “full” grid of data and want to set a “checkerboard” pattern of values in the data grid to a different color, or do you want to “intersperse” your data with a “checkerboard” pattern of values plotted as some constant color?
Update
It sounds like you want something more like a spreasheet? Matplotlib isn’t ideal for this, but you can do it.
Ideally, you’d just use
plt.table, but in this case, it’s easier to usematplotlib.table.Tabledirectly: