Python, matplotlib plot 2D histogram on polar axis.

In summary, the individual is seeking assistance from python/matplotlib experts to properly histogram and plot three vectors (azimuth, frequency, and power) on a polar axis. They have provided an example of their code and are experiencing issues with the histogram being distorted. They have tried using a scatter plot and a color mesh, but are not satisfied with the results. They have also mentioned trying the "bar" function without success. A picture of the desired output has been attached and they are looking for help with adjusting the colormap and corresponding color ranges to achieve the desired result.
  • #1
funcosed
37
0
Any python/matplotlib experts out there?? This one has been driving me crazy all day. I have three vectors, azimuth, frequency and power, which I would like to histogram and plot on a polar axis. I can plot a scatter plot this way no problem but the histogram gets messed up somehow. An example is below, anybody know how to do this properly??

import random
import numpy as np
import matplotlib.pyplot as plt

baz = np.zeros((20))
freq = np.zeros((20))
pwr = np.zeros((20))
for x in range(20):
baz[x] = random.randint(20,25)*10
freq[x] = random.randint(1,10)*10
pwr[x] = random.randint(-10,-1)*10

baz = baz*np.pi/180.

abins = np.linspace(0,2*np.pi,360)
sbins = np.linspace(1, 100)

H, xedges, yedges = np.histogram2d(baz, freq, bins=(abins,sbins), weights=pwr)

plt.figure(figsize=(14,14))
plt.subplot(111, polar=True)
#plt.scatter(baz, freq, c=pwr)
plt.pcolormesh(H)
plt.show()
 
Technology news on Phys.org
  • #2
I don't follow...what is it that you are trying to achieve? Can you show a picture? If I uncomment the scatter plot and comment out the colormesh, I do see a nice picture...it is just that colormesh covers the entire place...are you sure you want colormesh? or some other function? how about bar?
 
  • #3
Hi,
I've attached a link to a picture showing what I need, and I did try bar but couldn't get that to work properly either.
 
  • #4
Hhhhhmmm...maybe you just need to play around with the parameters of the mesh, you know, the colormap and which color correspond to which range...you should inspect the data you are plotting, maybe is too one sided or something
 
  • #5
solution here :)
 

1. How do I plot a 2D histogram on a polar axis using Python and matplotlib?

To plot a 2D histogram on a polar axis using Python and matplotlib, you can use the hist2d function from the pyplot module. This function takes in the x and y coordinates of your data points, as well as the number of bins you want to use, and returns a histogram plot on a polar axis.

2. Can I customize the appearance of my 2D histogram on a polar axis?

Yes, you can customize the appearance of your 2D histogram on a polar axis using various optional parameters in the hist2d function. For example, you can change the color scheme, add a colorbar, and adjust the size and shape of the bins.

3. How can I add labels and a title to my 2D histogram on a polar axis?

To add labels and a title to your 2D histogram on a polar axis, you can use the xlabel, ylabel, and title functions from the pyplot module. These functions take in a string as an argument, which will be displayed as the label or title on your plot.

4. Is it possible to plot multiple 2D histograms on the same polar axis?

Yes, it is possible to plot multiple 2D histograms on the same polar axis using the hist2d function. Simply call the function multiple times with different sets of data points and optional parameters, and all of the histograms will be displayed on the same plot.

5. Can I save my 2D histogram on a polar axis as an image file?

Yes, you can save your 2D histogram on a polar axis as an image file using the savefig function from the pyplot module. This function takes in the desired file name and file format as arguments, and will save the plot as an image file in your current working directory.

Similar threads

  • Programming and Computer Science
Replies
3
Views
927
  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
4
Views
3K
  • Programming and Computer Science
Replies
4
Views
4K
  • Programming and Computer Science
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
6
Views
853
  • Programming and Computer Science
Replies
3
Views
2K
  • Programming and Computer Science
Replies
21
Views
4K
Replies
5
Views
360
  • Advanced Physics Homework Help
Replies
7
Views
1K
Back
Top