# Plot histogram of Sobel operator magnitude and angle in OpenCV?

I want to plot histogram in OpenCV C++. The task is that x-axis should be angle and y-axis should be magnitude of histogram. I calculate magnitude and angle by using Sobel operator. Now how can I plot histogram by using magnitude and angle?

Thanks in advance. The simple code of problem is

// Read image
Mat img = imread("abs.jpg");
img.convertTo(img, CV_32F, 1 / 255.0);
/*GaussianBlur(img, img, Size(3, 3), 0, 0, BORDER_CONSTANT);*/
// Calculate gradients gx, gy
Mat gx, gy;
Sobel(img, gx, CV_32F, 1, 0, 1);
Sobel(img, gy, CV_32F, 0, 1, 1);

```
// C++ Calculate gradient magnitude and direction (in degrees)
Mat mag, angle;
```

cartToPolar(gx, gy, mag, angle, 1); imshow("magnitude of image is", mag); imshow("angle of image is", angle);

Take a look at the official histogram calculation example