2

I have a set of discrete densities, say n(i,j), and I'd like to plot a 3d bar-type visualization of it. My aim would be some figures like in the following links:

http://qutip.blogspot.de/2012/07/quantum-process-tomography.html

http://qutip.org/docs/2.2.0/guide/guide-visualization.html#visualizing-operators

I'd like to use directly Matlab, matploblib or gnuplot rather than using the qutip toolbox, specially because qutip installation is not very straightforward.

Any help is appropriated.

2 Answers 2

4

In matplotlib you could use bar3d. See the example in the gallery, although you'll need to set the color argument appropriately to get different colors for each bar - see the API docs.

Edit

Given the comment, the following code produces output without any reference to histograms:

x = np.array(range(0, 6), float) # I assume that np.loadtxt will give you (from the
y = x.copy()                     # comment) x,y as a 1d array in the form that this
xpos, ypos = np.meshgrid(x, y)   # script would after the xpos.flatten() lines.
z = np.random.rand(6, 6)         #
colors = ['b', 'g', 'y', 'r', 'k', 'c']*6 # This colors the bars individually
xpos = xpos.flatten()
ypos = ypos.flatten()
zpos = np.zeros_like(xpos)
dx = 0.5 * np.ones_like(zpos)
dy = dx.copy()
dz = z.flatten() # This is the actual data.
fig = plt.figure()
ax = fig.add_subplot(111,projection = '3d')
ax.bar3d(xpos, ypos, zpos, dx, dy, dz, color=colors)
Sign up to request clarification or add additional context in comments.

2 Comments

bar3d seems to plot the histogram. please have a look on my comment to the previous suggestion. can it be done with bar3d?
Thanks Ian, that was all I wanted. Now works perfect!
4

In Matlab, you can use bar3:

n = rand(4,5); %// example data
bar3(n)

See also view to change viewing angle of the 3D plot.

enter image description here

3 Comments

this seems the right command! I have the data file in the format i,j,n(i,j) which i,j=0-->5. I load the data with data=load('density.txt'); x=data(:,1) y=data(:,2) z=data(:,3); Q: with which arguments bar3 should be called with my data to represent exactly like this figure you have posted?
@Reza I'm not sure about your format. Which sizes do your x, y and z have?
x,y are of size 36 because I have (i,j) format so it is like (0,0),(0,1),...,(5,5) and z is corresponding density on each point. The python script solved what I wanted. However I'd be interested to know Matlab way also.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.