This page was generated from simple/example_bar.ipynb.
Interactive online version: Binder badge.

Note

This example requires the demo.nc file.

Bar plot demoΒΆ

This example shows you how to make a bar plot using the psyplot.project.plot.barplot method.

[1]:
import psyplot.project as psy
%matplotlib inline
%config InlineBackend.close_figures = False
[2]:
axes = iter(psy.multiple_subplots(2, 2, n=3))
for var in ['t2m', 'u', 'v']:
    psy.plot.barplot(
        'demo.nc',  # netCDF file storing the data
        name=var, # one plot for each variable
        y=[0, 1],  # two bars in total
        z=0, x=0,      # choose latitude and longitude as dimensions
        ylabel="{desc}",  # use the longname and units on the y-axis
        ax=next(axes),
        color='coolwarm', xticklabels='%B %Y',
        legendlabels='latitude %(y)1.2f $^\circ$N', legend='upper left',
        title='equally spaced'
    )
bars = psy.gcp(True)
bars.show()
/home/circleci/miniconda3/envs/docs/lib/python3.7/site-packages/psy_simple/plugin.py:423: MatplotlibDeprecationWarning:
The validate_legend_loc function was deprecated in Matplotlib 3.3 and will be removed two minor releases later.
  return {'loc': validate_legend_loc(value)}
/home/circleci/miniconda3/envs/docs/lib/python3.7/site-packages/psy_simple/plugin.py:423: MatplotlibDeprecationWarning:
The validate_legend_loc function was deprecated in Matplotlib 3.3 and will be removed two minor releases later.
  return {'loc': validate_legend_loc(value)}
/home/circleci/miniconda3/envs/docs/lib/python3.7/site-packages/psy_simple/plugin.py:423: MatplotlibDeprecationWarning:
The validate_legend_loc function was deprecated in Matplotlib 3.3 and will be removed two minor releases later.
  return {'loc': validate_legend_loc(value)}
../_images/simple_example_bar_2_1.png

The default is that all bars have the same width. You can however change that by setting the widths keyword to data

[3]:
bars(name='u').update(widths='data', xticks='month', title='data spaced')
bars.show()
../_images/simple_example_bar_4_0.png

Or you make a stacked plot

[4]:
bars(name='v').update(plot='stacked', title='stacked')
bars.show()
../_images/simple_example_bar_6_0.png
[5]:
psy.close('all')