Bar plot demo

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


In [1]:
import psyplot.project as psy
%matplotlib inline
%config InlineBackend.close_figures = False




In [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()


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


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


Or you make a stacked plot


In [4]:
bars(name='v').update(plot='stacked', title='stacked')
bars.show()



In [5]:
psy.close('all')