Draw a histogram plot

Hi,

I had tried to draw a histogram plot of the harp import product in a plot window using:

histogramplot(product, bins)

but I don’t know exactly how to run this function. I tried to give a different number of bins, for ex.
histogramplot(pro, ‘bins=100’),

and I always get this error:

Traceback (most recent call last):
File “”, line 1, in
File “C:\Users\yosef\anaconda3\lib\site-packages\visan\commands.py”, line 63, in histogramplot
x = numpy.transpose(numpy.reshape(numpy.concatenate([bins[:-1], bins[1:]]), (2, len(bins) - 1))).ravel()
IndexError: too many indices for array

Could you please by an example how to run this function to plot a histogram of the output data.

Thanks in advance

There is a histogram.py example script that comes with VISAN that shows you how to use the histogram plot. bins needs to be a numpy array containing the edge positions of the bins.

Thank you very much for your answer. I saw this example and tried to run it after changing with name of my output file, but it is not run. I see this error:

File “”, line 3
from visan.math import histogram
^
SyntaxError: multiple statements found while compiling a single statement

Are you running the script using the File -> “Load and Execute Script…” menu option?

Dear Sander,

I am so sorry for my late answer, I wasn’t paying attention to your question. Yes, I have run the script using this command, but I don’t know how to change the data on the x-axis to explain the tropospheric NO2 number density. Another problem is how to draw a histogram for each range separately as they are shown in the color bars.

for ex. in the attached figure, the tropospheric NO2 number density in the range [0 7e-05]

Regards

https://drive.google.com/file/d/1ik4NGIq1EP2bYqwnIwEdjCijdTXTQzpL/view?usp=sharing

https://drive.google.com/file/d/13z65q4bZNQgcZFAlZaw7vbBpQG90S7gK/view?usp=sharing

Please don’t use links to private google drive content. The figures are not accessible.

Dear Sander,

I am sorry for this mistake. Here are the previous figures.

Thank you very much.

colors_bar

NO2_histogram

You could do something like this:

from visan.math import histogram
num_bins = 200
bins = numpy.array(list(range(num_bins + 1)), dtype=float) * 7e-5 / num_bins
histogramplot(histogram(product.tropospheric_NO2_column_number_density.data, bins), bins)

Dear Sander,

Thanks so much for your help. I really appreciate this.
I have plotted a histogram for the product but what I see is inconsistent with the information on the image,

for ex. the tropospheric NO2 column number density in the range [6e-05 7e-05] looks less than the range in [5e-05 6e-05], while the image on the left shows the opposite.
Excuse me, do you any suggestions about that?

Kind regards

You have a lot of values above 7e-5. These will not show up in your histogram.

Yes, there is a lot of values above 7e-05, but I have selected this range to show the most clear image of the tropospheric NO2 column number density over Sweden on 1 March 2020, and I want to explain this in a histogram also. Do you an idea how to show this?

Dear Sander,

Excuse me, is there is any way to export the product as a numerical values, for example to save the output as a matrix of two columns, the first column contains the tropospheric NO2 column number density and the second column contains contains the accounts numbers. Or as a text file. It will easy to work with the data in any other analysing program.

Regards

HARP already has direct interfaces for many analysis applications (python, R, matlab, idl).

If you want to convert to something like .csv then first export the file using HARP to netcdf or hdf5 and then use something like described here to convert into other formats.

Thousand thanks Sander. I am very grateful for you. I greatly appreciate your help.

Dear Sander,

Using your notes I finished the monthly average histogram of the products, but the plot will be displayed on the visan window and I need to export the histogram to the python window for further processing.

Could you please help me to do this.

Best regards

You mean you want to see the numbers?
In that case use: print(histogram(product.tropospheric_NO2_column_number_density.data, bins))

I mean to display the histogram on the python screen after exporting it from the visan screen.

You cannot display graphs in the python console.
You might be referring to python notebooks. But if you want to use that, then just use python notebooks directly with HARP and something like matplotlib.

Thank so much. I will try.