<div dir="ltr"><div>try stdna.squeeze().plot() ?<br></div><div><br></div><div>I tried to make a minimum reproduction & I can't reproduce the error. Any chance you can share a binder or how you're getting your data?</div><div><br></div><div>This is what I tried:</div><div>slp = np.random.random(([1, 73,144]))<br>stdn = xr.Dataset({'slp': (['month', 'lat', 'lon'], slp)})<br>stdna = stdn.to_array()# must convert the xarray "dataset" to "dataArray"!!!<br><br>print(stdna.shape)<br><br>stdna = stdna.rename('Standardized SLP Anomaly')<br>ax = plt.axes(projection=ccrs.PlateCarree())<br>ax.coastlines(lw=1)<br>stdna.plot()</div><div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Mar 19, 2020 at 5:52 PM Benson, Randall <<a href="mailto:Randall.Benson@avangrid.com">Randall.Benson@avangrid.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div lang="EN-US">
<div class="gmail-m_-7935284670652492103WordSection1">
<p class="MsoNormal"><span style="font-size:9pt;font-family:"Calibri",sans-serif;color:rgb(56,86,35)">Hi -
<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:9pt;font-family:"Calibri",sans-serif;color:rgb(56,86,35)">I solved it by converting the datasets to dataarrays using this below with my variable a dataArray “stdna” and calling the “plot” command.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:9pt;font-family:"Calibri",sans-serif;color:rgb(56,86,35)">However, when I try to plot this variable using -- stdna.plot.contourf() – but I get an error saying my data must be 2D. The “stnda” variable looks like this –<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:9pt;font-family:"Calibri",sans-serif;color:rgb(56,86,35)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:9pt;font-family:"Calibri",sans-serif;color:rgb(56,86,35)">stdna<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:9pt;font-family:"Calibri",sans-serif;color:rgb(56,86,35)">Out[181]:
<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:9pt;font-family:"Calibri",sans-serif;color:rgb(56,86,35)"><xarray.DataArray 'Standardized SLP Anomaly' (variable: 1, month: 1, lat: 73, lon: 144)><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:9pt;font-family:"Calibri",sans-serif;color:rgb(56,86,35)">dask.array<stack, shape=(1, 1, 73, 144), dtype=float32, chunksize=(1, 1, 73, 144), chunktype=numpy.ndarray><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:9pt;font-family:"Calibri",sans-serif;color:rgb(56,86,35)">Coordinates:<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:9pt;font-family:"Calibri",sans-serif;color:rgb(56,86,35)"> * lon (lon) float32 0.0 2.5 5.0 7.5 10.0 ... 350.0 352.5 355.0 357.5<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:9pt;font-family:"Calibri",sans-serif;color:rgb(56,86,35)"> * lat (lat) float32 90.0 87.5 85.0 82.5 80.0 ... -82.5 -85.0 -87.5 -90.0<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:9pt;font-family:"Calibri",sans-serif;color:rgb(56,86,35)"> * month (month) int64 1<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:9pt;font-family:"Calibri",sans-serif;color:rgb(56,86,35)"> * variable (variable) <U3 'slp'<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:9pt;font-family:"Calibri",sans-serif;color:rgb(56,86,35)">--------------------------------------------------------------<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:9pt;font-family:"Calibri",sans-serif;color:rgb(56,86,35)">This works below….<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:9pt;font-family:"Calibri",sans-serif;color:rgb(56,86,35)">stdna = stdn.to_array()# must convert the xarray "dataset" to "dataArray"!!!<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:9pt;font-family:"Calibri",sans-serif;color:rgb(56,86,35)">#stdna.rename('Standardized SLP Anomaly')#rename dataarray<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:9pt;font-family:"Calibri",sans-serif;color:rgb(56,86,35)">stdna = stdna.rename('Standardized SLP Anomaly')#for legend description label<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:9pt;font-family:"Calibri",sans-serif;color:rgb(56,86,35)"># Define an axes object with a projection<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:9pt;font-family:"Calibri",sans-serif;color:rgb(56,86,35)">ax = plt.axes(projection=ccrs.PlateCarree())<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:9pt;font-family:"Calibri",sans-serif;color:rgb(56,86,35)"># Plot the coastline<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:9pt;font-family:"Calibri",sans-serif;color:rgb(56,86,35)">ax.coastlines(lw=1)
<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:9pt;font-family:"Calibri",sans-serif;color:rgb(56,86,35)">stdna.plot()<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:9pt;font-family:"Calibri",sans-serif;color:rgb(56,86,35)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:9pt;font-family:"Calibri",sans-serif;color:rgb(56,86,35)">#<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:9pt;font-family:"Calibri",sans-serif;color:rgb(56,86,35)"><u></u> <u></u></span></p>
<p class="MsoNormal"><b><span style="font-size:11pt;font-family:"Calibri",sans-serif">From:</span></b><span style="font-size:11pt;font-family:"Calibri",sans-serif"> Hannah <<a href="mailto:story645@gmail.com" target="_blank">story645@gmail.com</a>>
<br>
<b>Sent:</b> Thursday, March 19, 2020 1:32 PM<br>
<b>To:</b> Benson, Randall <<a href="mailto:Randall.Benson@avangrid.com" target="_blank">Randall.Benson@avangrid.com</a>><br>
<b>Cc:</b> Matplotlib-users <<a href="mailto:matplotlib-users@python.org" target="_blank">matplotlib-users@python.org</a>><br>
<b>Subject:</b> Re: EXTERNAL: Re: [Matplotlib-users] Variability Plots Matplotlib NetCDF4 Data<u></u><u></u></span></p>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal">Hi, <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">Sorry for the late reply, been swamped. If you haven't sorted this out, can you please post at least some of the code that generated this error?
<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">Thanks!<u></u><u></u></p>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal">On Tue, Mar 17, 2020 at 1:06 AM Benson, Randall <<a href="mailto:Randall.Benson@avangrid.com" target="_blank">Randall.Benson@avangrid.com</a>> wrote:<u></u><u></u></p>
</div>
<blockquote style="border-color:currentcolor currentcolor currentcolor rgb(204,204,204);border-style:none none none solid;border-width:medium medium medium 1pt;padding:0in 0in 0in 6pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<p class="MsoNormal"><span style="font-size:9pt;font-family:"Calibri",sans-serif;color:rgb(56,86,35)">Hi Hannah –
</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:9pt;font-family:"Calibri",sans-serif;color:rgb(56,86,35)"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:9pt;font-family:"Calibri",sans-serif;color:rgb(56,86,35)">Are you familiar with this error using xarray to plot gridded netcd4 data?
</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:9pt;font-family:"Calibri",sans-serif;color:rgb(36,39,41);background:white none repeat scroll 0% 0%"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:9pt;font-family:"Calibri",sans-serif;color:rgb(36,39,41);background:white none repeat scroll 0% 0%">This is the out from “stdn.var”
</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:9pt;font-family:"Calibri",sans-serif;color:rgb(36,39,41);background:white none repeat scroll 0% 0%"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:9pt;font-family:"Calibri",sans-serif;color:rgb(56,86,35)"><bound method ImplementsDatasetReduce._reduce_method.<locals>.wrapped_func of <xarray.Dataset></span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:9pt;font-family:"Calibri",sans-serif;color:rgb(56,86,35)">Dimensions: (lat: 73, lon: 144, month: 1)</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:9pt;font-family:"Calibri",sans-serif;color:rgb(56,86,35)">Coordinates:</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:9pt;font-family:"Calibri",sans-serif;color:rgb(56,86,35)"> * month (month) int64 2</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:9pt;font-family:"Calibri",sans-serif;color:rgb(56,86,35)"> * lon (lon) float32 0.0 2.5 5.0 7.5 10.0 ... 350.0 352.5 355.0 357.5</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:9pt;font-family:"Calibri",sans-serif;color:rgb(56,86,35)"> * lat (lat) float32 90.0 87.5 85.0 82.5 80.0 ... -82.5 -85.0 -87.5 -90.0</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:9pt;font-family:"Calibri",sans-serif;color:rgb(56,86,35)">Data variables:</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:9pt;font-family:"Calibri",sans-serif;color:rgb(56,86,35)"> slp (month, lat, lon) float32 dask.array<chunksize=(1, 73, 144), meta=np.ndarray>></span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:9pt;font-family:"Calibri",sans-serif;color:rgb(56,86,35)"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:9pt;font-family:"Calibri",sans-serif;color:rgb(56,87,35);background:white none repeat scroll 0% 0%">I keep getting this error –</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:9pt;font-family:"Calibri",sans-serif;color:rgb(56,87,35);background:white none repeat scroll 0% 0%">- AttributeError: '_Dataset_PlotMethods' object has no attribute 'contourf'</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:9pt;font-family:"Calibri",sans-serif;color:rgb(56,87,35);background:white none repeat scroll 0% 0%"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:9pt;font-family:"Calibri",sans-serif;color:rgb(56,87,35);background:white none repeat scroll 0% 0%">Thank you,</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:9pt;font-family:"Calibri",sans-serif;color:rgb(56,87,35);background:white none repeat scroll 0% 0%">Randall</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:9pt;font-family:"Calibri",sans-serif;color:rgb(56,86,35)"> </span><u></u><u></u></p>
<p class="MsoNormal"><b><span style="font-size:11pt;font-family:"Calibri",sans-serif">From:</span></b><span style="font-size:11pt;font-family:"Calibri",sans-serif"> Hannah <<a href="mailto:story645@gmail.com" target="_blank">story645@gmail.com</a>>
<br>
<b>Sent:</b> Wednesday, March 11, 2020 4:28 PM<br>
<b>To:</b> Benson, Randall <<a href="mailto:Randall.Benson@avangrid.com" target="_blank">Randall.Benson@avangrid.com</a>><br>
<b>Cc:</b> Matplotlib-users <<a href="mailto:matplotlib-users@python.org" target="_blank">matplotlib-users@python.org</a>><br>
<b>Subject:</b> EXTERNAL: Re: [Matplotlib-users] Variability Plots Matplotlib NetCDF4 Data</span><u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<div>
<div>
<p class="MsoNormal">Hi Randall,<u></u><u></u></p>
<div>
<p class="MsoNormal">I'm not sure what specifically you're asking for. Are you using xarray (<a href="http://xarray.pydata.org/en/stable/" target="_blank">http://xarray.pydata.org/en/stable/</a>) ?
If not, it might help in more efficiently computing the anomolies once you read all the files into an xarray:<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<p class="MsoNormal" style="margin-bottom:12pt"><a href="http://xarray.pydata.org/en/stable/examples/weather-data.html#Calculate-monthly-anomalies" target="_blank">http://xarray.pydata.org/en/stable/examples/weather-data.html#Calculate-monthly-anomalies</a><u></u><u></u></p>
<div>
<div>
<p class="MsoNormal">On Wed, Mar 11, 2020, 4:17 PM Benson, Randall <<a href="mailto:Randall.Benson@avangrid.com" target="_blank">Randall.Benson@avangrid.com</a>> wrote:<u></u><u></u></p>
</div>
<blockquote style="border-style:none none none solid;border-width:medium medium medium 1pt;padding:0in 0in 0in 6pt;margin:5pt 0in 5pt 4.8pt;border-color:currentcolor currentcolor currentcolor rgb(204,204,204)">
<div>
<div>
<p class="MsoNormal"><span style="font-size:9pt;font-family:"Arial",sans-serif;color:rgb(59,56,56)">HI-
</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:9pt;font-family:"Arial",sans-serif;color:rgb(59,56,56)"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:9pt;font-family:"Arial",sans-serif;color:rgb(59,56,56)">I’m trying to develop monthly standardized anomaly plots of Sea Level Pressure (SLP) using NCEP reanalysis
data in netCDF4 format. I can plot netCDF4 data for a single month in plot form like the example shown below. However, I need to construct average SLP plots for each month given a set of years and use those to plot the standardized anomalies for each month
of the current year. So, I’m looking too for just examples (python code) of creating variability plots using gridded data in Matplotlib. Thank you!</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:9pt;font-family:"Arial",sans-serif;color:rgb(59,56,56)"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:9pt;font-family:"Arial",sans-serif;color:rgb(59,56,56)">Randall Benson</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:9pt;font-family:"Arial",sans-serif;color:rgb(59,56,56)"> </span><u></u><u></u></p>
<p class="MsoNormal"><u></u><u></u></p>
<table cellspacing="0" cellpadding="0" border="0" align="left">
<tbody>
<tr style="height:102pt">
<td colspan="2" style="padding:0.75pt;height:102pt">
<p class="MsoNormal">
<u></u><u></u></p>
</td>
</tr>
<tr>
<td colspan="2" style="padding:0.75pt 0.75pt 0.75pt 20.25pt">
<p class="MsoNormal">
<b><span style="font-size:8pt;font-family:"Arial",sans-serif;color:rgb(92,136,26)">Randall P. Benson, PhD</span></b><span style="font-size:8pt;font-family:"Arial",sans-serif;color:rgb(92,136,26)">
<br>
Wind Asset Meteorologist, Energy Resource - Onshore<br>
<br>
1125 NW Couch Street, Suite 700</span><u></u><u></u></p>
<p class="MsoNormal">
<span style="font-size:8pt;font-family:"Arial",sans-serif;color:rgb(92,136,26)">Portland, Oregon, USA 97209
<br>
Telephone 503-796-7129<br>
Cell 971-227-2477 <br>
<a href="mailto:randall.benson@avangrid.com" target="_blank">randall.benson@avangrid.com</a>
</span><u></u><u></u></p>
</td>
</tr>
<tr style="height:27pt">
<td style="width:45pt;padding:0.75pt 0.75pt 0.75pt 20.25pt;height:27pt" width="60">
<p class="MsoNormal">
<span style="color:rgb(59,56,56)"><br>
</span><u></u><u></u></p>
</td>
<td style="width:195pt;padding:0.75pt 0.75pt 0.75pt 4.5pt;height:27pt" width="260">
<p class="MsoNormal">
<span style="font-size:7.5pt;font-family:"Arial",sans-serif;color:rgb(92,136,26)"><br>
In the interest of the environment, <br>
please print only if necessary and recycle. </span><u></u><u></u></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal"><span style="color:rgb(59,56,56)"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="color:rgb(59,56,56)"> </span><u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
</div>
<table cellpadding="0" border="0">
<tbody>
<tr>
<td style="background:white none repeat scroll 0% 0%;padding:0.75pt">
<pre><span style="color:black">==============================================================</span><u></u><u></u></pre>
<pre><span style="color:black"> </span><u></u><u></u></pre>
<pre><span style="color:black">Please consider the environment before printing this email.</span><u></u><u></u></pre>
<pre><span style="color:black"> </span><u></u><u></u></pre>
<pre><span style="color:black">If you have received this message in error, please notify the sender and immediately delete this message and any attachment hereto and/or copy hereof, as such message contains confidential information intended solely for the individual or entity to whom it is addressed. The use or disclosure of such information to third parties is prohibited by law and may give rise to civil or criminal liability.</span><u></u><u></u></pre>
<pre><span style="color:black"> </span><u></u><u></u></pre>
<pre><span style="color:black">The views presented in this message are solely those of the author(s) and do not necessarily represent the opinion of Avangrid Renewables, LLC. or any company of its group. Neither Avangrid Renewables, LLC. nor any company of its group guarantees the integrity, security or proper receipt of this message. Likewise, neither Avangrid Renewables, LLC. nor any company of its group accepts any liability whatsoever for any possible damages arising from, or in connection with, data interception, software viruses or manipulation by third parties.</span><u></u><u></u></pre>
<pre><span style="color:black"> </span><u></u><u></u></pre>
<pre><span style="color:black"> ==============================================================</span><u></u><u></u></pre>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal">_______________________________________________<br>
Matplotlib-users mailing list<br>
<a href="mailto:Matplotlib-users@python.org" target="_blank">Matplotlib-users@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/matplotlib-users" target="_blank">https://mail.python.org/mailman/listinfo/matplotlib-users</a><u></u><u></u></p>
</blockquote>
</div>
</div>
</div>
</div>
</div>
<table cellpadding="0" border="0">
<tbody>
<tr>
<td style="background:white none repeat scroll 0% 0%;padding:0.75pt">
<pre><span style="color:black">==============================================================<u></u><u></u></span></pre>
<pre><span style="color:black"> <u></u><u></u></span></pre>
<pre><span style="color:black">Please consider the environment before printing this email.<u></u><u></u></span></pre>
<pre><span style="color:black"><u></u> <u></u></span></pre>
<pre><span style="color:black">If you have received this message in error, please notify the sender and immediately delete this message and any attachment hereto and/or copy hereof, as such message contains confidential information intended solely for the individual or entity to whom it is addressed. The use or disclosure of such information to third parties is prohibited by law and may give rise to civil or criminal liability.<u></u><u></u></span></pre>
<pre><span style="color:black"><u></u> <u></u></span></pre>
<pre><span style="color:black">The views presented in this message are solely those of the author(s) and do not necessarily represent the opinion of Avangrid Renewables, LLC. or any company of its group. Neither Avangrid Renewables, LLC. nor any company of its group guarantees the integrity, security or proper receipt of this message. Likewise, neither Avangrid Renewables, LLC. nor any company of its group accepts any liability whatsoever for any possible damages arising from, or in connection with, data interception, software viruses or manipulation by third parties.<u></u><u></u></span></pre>
<pre><span style="color:black"><u></u> <u></u></span></pre>
<pre><span style="color:black"> ==============================================================<u></u><u></u></span></pre>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal"><u></u> <u></u></p>
</blockquote>
</div>
</div>
</div>
<table><tbody><tr><td bgcolor="#ffffff"><font color="#000000"><pre>==============================================================
Please consider the environment before printing this email.
If you have received this message in error, please notify the sender and immediately delete this message and any attachment hereto and/or copy hereof, as such message contains confidential information intended solely for the individual or entity to whom it is addressed. The use or disclosure of such information to third parties is prohibited by law and may give rise to civil or criminal liability.
The views presented in this message are solely those of the author(s) and do not necessarily represent the opinion of Avangrid Renewables, LLC. or any company of its group. Neither Avangrid Renewables, LLC. nor any company of its group guarantees the integrity, security or proper receipt of this message. Likewise, neither Avangrid Renewables, LLC. nor any company of its group accepts any liability whatsoever for any possible damages arising from, or in connection with, data interception, software viruses or manipulation by third parties.
==============================================================</pre></font></td></tr></tbody></table></blockquote></div></div>