Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Colorplot of 2D array matplotlib

So, I thought this was going to be really simple, but I've been having a lot of difficult finding exactly what I'm looking for in a comprehensible example.

Basically I want to make phase plots, so assuming I have a 2d array, how can I get matplotlib to convert this to a plot that I can attach titles, axes, and legends (color bars) to.

I'm looking for an extremely simple bare bones solution that only uses what is required that will work with any 2D array.

I'm certain this is simple and I'm just being thick somehow, but I'm really having a lot of trouble with this.

I have been tooling with the examples, but they don't seem well suited to what I'm trying to do: I like the general appearance of this graph, I'd just like to be able to pass in a 2dArray and have this same result:

import numpy as np import matplotlib as ml import matplotlib.pyplot as plt  H = [[1,2,3,4][5,6,7,8][9,10,11,12][13,14,15,16]]  fig = plt.figure(figsize=(6, 3.2))  ax = fig.add_subplot(111) ax.set_title('colorMap') X,Y = np.meshgrid(xedges, yedges) plt.pcolormesh(X, Y, H) ax.set_aspect('equal')  cax = fig.add_axes([0.12, 0.1, 0.78, 0.8]) cax.get_xaxis().set_visible(False) cax.get_yaxis().set_visible(False) cax.patch.set_alpha(0) cax.set_frame_on(False) plt.colorbar(orientation='vertical') plt.show() 
like image 557
Slater Victoroff Avatar asked May 11 '13 01:05

Slater Victoroff


People also ask

What is YLIM in Matplotlib?

ylim() Function. The ylim() function in pyplot module of matplotlib library is used to get or set the y-limits of the current axes. Syntax: matplotlib.pyplot.ylim(*args, **kwargs) Parameters: This method accept the following parameters that are described below: bottom: This parameter is used to set the ylim to bottom.

How do I plot multiple lines in Matplotlib?

Import matplotlib. To create subplot, use subplots() function. Next, define data coordinates using range() function to get multiple lines with different lengths. To plot a line chart, use the plot() function.


1 Answers

I'm afraid your posted example is not working, since X and Y aren't defined. So instead of pcolormesh let's use imshow:

import numpy as np import matplotlib.pyplot as plt  H = np.array([[1, 2, 3, 4],               [5, 6, 7, 8],               [9, 10, 11, 12],               [13, 14, 15, 16]])  # added some commas and array creation code  fig = plt.figure(figsize=(6, 3.2))  ax = fig.add_subplot(111) ax.set_title('colorMap') plt.imshow(H) ax.set_aspect('equal')  cax = fig.add_axes([0.12, 0.1, 0.78, 0.8]) cax.get_xaxis().set_visible(False) cax.get_yaxis().set_visible(False) cax.patch.set_alpha(0) cax.set_frame_on(False) plt.colorbar(orientation='vertical') plt.show() 
like image 160
heltonbiker Avatar answered Sep 23 '22 16:09

heltonbiker