# Draw a histogram plot

**URL:** https://forum.atmospherictoolbox.org/t/draw-a-histogram-plot/157
**Category:** Uncategorized
**Created:** [June 4, 2020, 9:27am UTC](https://forum.atmospherictoolbox.org/t/draw-a-histogram-plot/157 "2020-06-04T09:27:00Z")
**Posts on this page:** 19
**Page:** 1

<div class="post-metadata">

### Author: ![Yosef](https://forum.atmospherictoolbox.org/letter_avatar_proxy/v4/letter/y/53a042/32.png) [@Yosef](https://forum.atmospherictoolbox.org/u/Yosef)
#### Post date: [June 4, 2020, 9:27am UTC](https://forum.atmospherictoolbox.org/t/draw-a-histogram-plot/157/1 "2020-06-04T09:27:01Z")

</div>

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

---

<div class="post-metadata">

### Author: ![sander.niemeijer](https://forum.atmospherictoolbox.org/user_avatar/forum.atmospherictoolbox.org/sander.niemeijer/32/5_2.png) [@sander.niemeijer](https://forum.atmospherictoolbox.org/u/sander.niemeijer)
#### Post date: [June 4, 2020, 11:52am UTC](https://forum.atmospherictoolbox.org/t/draw-a-histogram-plot/157/2 "2020-06-04T11:52:17Z")

</div>

There is a [histogram.py example script](https://github.com/stcorp/visan/blob/master/visan/examples/histogram.py) 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.

---

<div class="post-metadata">

### Author: ![Yosef](https://forum.atmospherictoolbox.org/letter_avatar_proxy/v4/letter/y/53a042/32.png) [@Yosef](https://forum.atmospherictoolbox.org/u/Yosef)
#### Post date: [June 5, 2020, 8:41am UTC](https://forum.atmospherictoolbox.org/t/draw-a-histogram-plot/157/3 "2020-06-05T08:41:15Z")

</div>

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

---

<div class="post-metadata">

### Author: ![sander.niemeijer](https://forum.atmospherictoolbox.org/user_avatar/forum.atmospherictoolbox.org/sander.niemeijer/32/5_2.png) [@sander.niemeijer](https://forum.atmospherictoolbox.org/u/sander.niemeijer)
#### Post date: [June 5, 2020, 9:08am UTC](https://forum.atmospherictoolbox.org/t/draw-a-histogram-plot/157/4 "2020-06-05T09:08:59Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Yosef](https://forum.atmospherictoolbox.org/letter_avatar_proxy/v4/letter/y/53a042/32.png) [@Yosef](https://forum.atmospherictoolbox.org/u/Yosef)
#### Post date: [June 7, 2020, 12:11pm UTC](https://forum.atmospherictoolbox.org/t/draw-a-histogram-plot/157/5 "2020-06-07T12:11:11Z")

</div>

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/1ik4NGIq1EP2bYqwnIwEdjCijdTXTQzpL/view?usp=sharing)

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

---

<div class="post-metadata">

### Author: ![sander.niemeijer](https://forum.atmospherictoolbox.org/user_avatar/forum.atmospherictoolbox.org/sander.niemeijer/32/5_2.png) [@sander.niemeijer](https://forum.atmospherictoolbox.org/u/sander.niemeijer)
#### Post date: [June 8, 2020, 6:09am UTC](https://forum.atmospherictoolbox.org/t/draw-a-histogram-plot/157/6 "2020-06-08T06:09:13Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Yosef](https://forum.atmospherictoolbox.org/letter_avatar_proxy/v4/letter/y/53a042/32.png) [@Yosef](https://forum.atmospherictoolbox.org/u/Yosef)
#### Post date: [June 8, 2020, 9:15am UTC](https://forum.atmospherictoolbox.org/t/draw-a-histogram-plot/157/7 "2020-06-08T09:15:33Z")

</div>

Dear Sander,

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

Thank you very much.

![colors_bar](https://forum.atmospherictoolbox.org/uploads/default/original/1X/c14165f42a4f1fcd391bcf25a15675d899d3171e.png)

![NO2_histogram](https://forum.atmospherictoolbox.org/uploads/default/original/1X/45d7e557331a57b941837f6b9f9ae31086d390a9.jpeg)

---

<div class="post-metadata">

### Author: ![sander.niemeijer](https://forum.atmospherictoolbox.org/user_avatar/forum.atmospherictoolbox.org/sander.niemeijer/32/5_2.png) [@sander.niemeijer](https://forum.atmospherictoolbox.org/u/sander.niemeijer)
#### Post date: [June 8, 2020, 9:38am UTC](https://forum.atmospherictoolbox.org/t/draw-a-histogram-plot/157/8 "2020-06-08T09:38:57Z")

</div>

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)
```

---

<div class="post-metadata">

### Author: ![Yosef](https://forum.atmospherictoolbox.org/letter_avatar_proxy/v4/letter/y/53a042/32.png) [@Yosef](https://forum.atmospherictoolbox.org/u/Yosef)
#### Post date: [June 8, 2020, 11:44am UTC](https://forum.atmospherictoolbox.org/t/draw-a-histogram-plot/157/9 "2020-06-08T11:44:37Z")

</div>

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,

 ![NO2_Sverige](https://forum.atmospherictoolbox.org/uploads/default/original/1X/7331eddb7c7ace594f041d21d9752c2e05cc977b.jpeg) 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

---

<div class="post-metadata">

### Author: ![sander.niemeijer](https://forum.atmospherictoolbox.org/user_avatar/forum.atmospherictoolbox.org/sander.niemeijer/32/5_2.png) [@sander.niemeijer](https://forum.atmospherictoolbox.org/u/sander.niemeijer)
#### Post date: [June 8, 2020, 1:42pm UTC](https://forum.atmospherictoolbox.org/t/draw-a-histogram-plot/157/10 "2020-06-08T13:42:10Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Yosef](https://forum.atmospherictoolbox.org/letter_avatar_proxy/v4/letter/y/53a042/32.png) [@Yosef](https://forum.atmospherictoolbox.org/u/Yosef)
#### Post date: [June 8, 2020, 2:17pm UTC](https://forum.atmospherictoolbox.org/t/draw-a-histogram-plot/157/11 "2020-06-08T14:17:03Z")

</div>

> [@Yosef](#):
>
> the tropospheric NO2 column number density

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?

---

<div class="post-metadata">

### Author: ![Yosef](https://forum.atmospherictoolbox.org/letter_avatar_proxy/v4/letter/y/53a042/32.png) [@Yosef](https://forum.atmospherictoolbox.org/u/Yosef)
#### Post date: [June 9, 2020, 9:44am UTC](https://forum.atmospherictoolbox.org/t/draw-a-histogram-plot/157/12 "2020-06-09T09:44:33Z")

</div>

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

---

<div class="post-metadata">

### Author: ![sander.niemeijer](https://forum.atmospherictoolbox.org/user_avatar/forum.atmospherictoolbox.org/sander.niemeijer/32/5_2.png) [@sander.niemeijer](https://forum.atmospherictoolbox.org/u/sander.niemeijer)
#### Post date: [June 9, 2020, 10:03am UTC](https://forum.atmospherictoolbox.org/t/draw-a-histogram-plot/157/13 "2020-06-09T10:03:52Z")

</div>

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](https://confluence.ecmwf.int/display/CKB/How+to+convert+NetCDF+to+CSV) to convert into other formats.

---

<div class="post-metadata">

### Author: ![Yosef](https://forum.atmospherictoolbox.org/letter_avatar_proxy/v4/letter/y/53a042/32.png) [@Yosef](https://forum.atmospherictoolbox.org/u/Yosef)
#### Post date: [June 9, 2020, 12:56pm UTC](https://forum.atmospherictoolbox.org/t/draw-a-histogram-plot/157/14 "2020-06-09T12:56:03Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Yosef](https://forum.atmospherictoolbox.org/letter_avatar_proxy/v4/letter/y/53a042/32.png) [@Yosef](https://forum.atmospherictoolbox.org/u/Yosef)
#### Post date: [June 11, 2020, 12:01pm UTC](https://forum.atmospherictoolbox.org/t/draw-a-histogram-plot/157/15 "2020-06-11T12:01:33Z")

</div>

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

---

<div class="post-metadata">

### Author: ![sander.niemeijer](https://forum.atmospherictoolbox.org/user_avatar/forum.atmospherictoolbox.org/sander.niemeijer/32/5_2.png) [@sander.niemeijer](https://forum.atmospherictoolbox.org/u/sander.niemeijer)
#### Post date: [June 11, 2020, 12:14pm UTC](https://forum.atmospherictoolbox.org/t/draw-a-histogram-plot/157/16 "2020-06-11T12:14:07Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Yosef](https://forum.atmospherictoolbox.org/letter_avatar_proxy/v4/letter/y/53a042/32.png) [@Yosef](https://forum.atmospherictoolbox.org/u/Yosef)
#### Post date: [June 11, 2020, 12:22pm UTC](https://forum.atmospherictoolbox.org/t/draw-a-histogram-plot/157/17 "2020-06-11T12:22:51Z")

</div>

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

---

<div class="post-metadata">

### Author: ![sander.niemeijer](https://forum.atmospherictoolbox.org/user_avatar/forum.atmospherictoolbox.org/sander.niemeijer/32/5_2.png) [@sander.niemeijer](https://forum.atmospherictoolbox.org/u/sander.niemeijer)
#### Post date: [June 11, 2020, 12:50pm UTC](https://forum.atmospherictoolbox.org/t/draw-a-histogram-plot/157/18 "2020-06-11T12:50:18Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Yosef](https://forum.atmospherictoolbox.org/letter_avatar_proxy/v4/letter/y/53a042/32.png) [@Yosef](https://forum.atmospherictoolbox.org/u/Yosef)
#### Post date: [June 11, 2020, 12:52pm UTC](https://forum.atmospherictoolbox.org/t/draw-a-histogram-plot/157/19 "2020-06-11T12:52:04Z")

</div>

Thank so much. I will try.
