'python equivalent code for matlab histogram

I am manually trying to convert a matlab code to Python for my application. The Matlab code is this:

% BUILD HISTOGRAM

% Specify bin centers of the histogram
bin_c=-0.58:0.04:0.58;

% Three dimensional histogram of bivariate data 
Z = hist3(dRRnew, {bin_c bin_c});

Z(14,15:16)=0;
Z(15:16,14:17)=0;
Z(17,15:16)=0;

Can I get some help in writing in the python equivalent code?

Edited

I used the matlab2python tool to convert matlab code to python and the resulting code was as follows:

# BUILD HISTOGRAM

# Specify bin centers of the histogram
bin_c = np.arange(- 0.58,0.58+0.04,0.04)

# Three dimensional histogram of bivariate data
Z = hist3(dRRnew,np.array([bin_c,bin_c]))

[X,Y]=meshgrid(-0.58:0.04:0.58, -0.58:0.04:0.58);
surf(X,Y, Z);
axis tight
xlabel('dRR(i-1)')
ylabel('dRR(i)')

But i checked the matplotlib docs, there is no in-built function hist3.



Solution 1:[1]

I think you might be looking for hist3d() that is part of the matplotlib package. I would also suggest carefully looking through what the translator has kicked out as I think you'll also have issues with surf and xlabel and ylabel as well.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 liamcsmith