pmlmodelling / nctoolkit

A Python package for netCDF analysis and post-processing
https://nctoolkit.readthedocs.io/en/latest/
GNU General Public License v3.0
77 stars 10 forks source link

Subplots using nctoolkit #119

Open pravee3 opened 2 weeks ago

pravee3 commented 2 weeks ago

Hello,

I have recently started using nctoolkit for some analysis. I wanted to generate some subplots using pub_plot and tried it with matplotlib subplot options but it doesn't seem to work with nctoolkit. Is there a way we can make subplots? and also can modify texts and axis or make colorbar False in pub_plot?

Thanks

robertjwilson commented 2 weeks ago

Thanks for using the package @pravee3.

I'm guessing you are referring to panel plots. You can do this by passing fig and gs args to pub_plot. The example below will give you a starting point.

import nctoolkit as nc
from matplotlib import pyplot as plt
gs = plt.GridSpec(1, 2)

fig = plt.figure(figsize=(10, 10))
ds = nc.open_thredds("https://psl.noaa.gov/thredds/dodsC/Datasets/COBE2/sst.mon.mean.nc")
ds.subset(time = 0)

ds.pub_plot(fig = fig, gs = gs[0,0], title = "time 0")
ds = nc.open_thredds("https://psl.noaa.gov/thredds/dodsC/Datasets/COBE2/sst.mon.mean.nc")
ds.subset(time = 1)
ds.pub_plot(fig = fig, gs = gs[0,1], title = "time 1")

This will give you this, but of course you'll need to play around with the gs and fig to get things formatted nicely.

image

This is currently an undocumented feature as I need a smarter way to do things.

I believe the code above also gives you the answer to the second question. Just pass fig to pub_plot and then you should be able to modify things using matplotlib options.

I hope that helps.

pravee3 commented 2 weeks ago

Thank you, Robert. That does help. Looking forward to have some more features in pub_plot to generate some quality figures. I have tried your suggestion and able to get a nice plot but still struggling to control few things here like how can I remove colorbar of first panel and also bring xticks on the bottom instead of top or maybe add a ylabel using the pub_plot?

Thanks