coastlines don't display using cartopy - cartopy

I am new to cartopy and tried the examples in the documentation (e.g. http://scitools.org.uk/cartopy/docs/latest/examples/waves.py ). The colour plot displays fine, however, the coastlines are missing when I run the example.
I'm using anaconda on windows and tried installing cartopy via Christoph Gohlke's binaries as well as Rich Signell's conda package on binstar (both of which seem to be the same, resulting in version '0.11.x'). My matplotlib version is '1.3.1'.
How can I get the coastlines to display? Is there anything missing in my installation?
Thanks!

This has been fixed and the package uploaded to the scitools binstar channel. This issue reflects the change in the url of files on the natural earth website (i.e. changing under our feet).

Related

Mplot3D plot freezes when plotting in PyCharm Professional

Recently when I am doing MatPlotLib 3D plots in PyCharm, the debugging and the plot window are freezing when excuting the plt.show() command. In the top bar of the plot is mentioned (Not Responding). This happens both in PyCharm Community edition 2019 and PyCharm Professional 2021. I am running v3.8 of Python. If I execute plt.show(Block=True), the interactive 3D plot will come up, but I will need to close the figure to continue the debugging.
Does anyone have an idea how I can plot the figure with plt.show(), get up the interactive window, and continue debugging while still having the interactive window open? This worked in my previous version of Python v3.7, but the problem happened recently when upgrading to v3.8.
I recently faced the same issue when using matplotlib to plot. This seems to be related to a change in the order of precedence that matplotlib uses to pick its default backend. According to the matplotlibrc file that is bundled with the Python package, the order used to be
MacOSX Qt5Agg Gtk3Agg TkAgg WxAgg Agg
in previous versions (e.g., v3.4.2), while in more recent versions (e.g., v3.5.0) it has been be changed to
MacOSX QtAgg Gtk4Agg Gtk3Agg TkAgg WxAgg Agg
For me, setting the backend to Qt5Agg right after importing matplotlib in Python via
import matplotlib
matplotlib.use("Qt5Agg")
indeed solved the "Not responding" issue. Alternatively, we can specify it through the environment variable MPLBACKEND=Qt5Agg.
Likely, we could also set Qt5Agg as default backend in matplotlibrc either by modifying the bundled matplotlibrc file or by providing our own.
PS: Not sure whether the core issue that prevents the QtAgg backend from working correctly is in PyCharm, matplotlib, or PyQt...

Getting GRIB2 Lat/Lon Information from GDAL

I am attempting to plot fields from a GRIB2 file of GFS model data (example file: https://nomads.ncep.noaa.gov/pub/data/nccf/com/gfs/prod/gfs.20220202/12/atmos/gfs.t12z.pgrb2.0p25.f006 ). Normally I would just use PyGRIB and I'd have this problem solved yesterday, but I am on Windows (because it's what my employer uses, so I'm stuck with it and have to make this work on a Windows environment) and Windows and PyGRIB don't play nice. I am able to open the GRIB2 file and even plot variables over the entire domain using GDAL. The only problem is I need a way to get an array of the latitude and longitude values at each grid point (similar to in PyGRIB doing .latlons() on a GRIB message) so I can plot a subset of the domain.
Basically, I'm trying to replicate what is being done in this video, and need the data (got it using dataset.GetRasterBand(269).ReadAsArray()), then the lat/lon information.
I also tried using xarray, but Windows doesn't play nice with xarray either.
Given your comfort with PyGRIB, I'd say the solution is to use Conda and install it on Windows. You can use conda-forge's miniforge to install conda. Then, however you get Conda, install pygrib with:
conda install -c conda-forge pygrib

matplotlib plots fail silently in vscode but work from the python interpreter in the same environment

Until today, matplotlib was working with vscode. TOday I updated vscode to the latest version and found that plots don't work. They work from the same virtual environment using the python interpreter but not from vscode. I rolled back to earlier versions of both matplotlib and vscode, but it still doesn't work. Here is my code to plot:
import matplotlib
import matplotlib.pyplot as plt
plt.plot([1,2],[3,4])
plt.show()
The version of vscode is 1.53.2 and the version of matplotlib is 3.3.4
If I call plt.savefig, it saves the figure. It just doesn't display interactively.
I have tried this with multiple virtual envioronments and multiple vscode workspaces, all of which worked before today.
VSCode doesn't see my DISPLAY environment variable on my Linux system, so it is running headless. I can make plots work by giving the command "export DISPLAY=:0" in the vscode terminal window. I would like to have this happen automatically but I don't know how to make that happen.
The way I discovered this was by inserting "matplotlib.use("TKAgg")" in my python script. This elicited a message saying that I was running headless.
The way I found the correct value for DISPLAY was to examine that variable in a terminal window outside of vscode.
When I went to report this on the vscode Github page, I found the suggestion to disable all extensions. When I do that, I don't have to set DISPLAY. I then went and reenabled all extensions, and plotting still works, so it seems the fix was to disable and reenable all extensions.

VSCode 'default dark' theme doesn't automatically defaults the matplotlib style to 'dark_background'

Summary
When figure is drawn with matplotlib using VSCode Jupyter Notebook, the figure is rendered in light theme even when the VSCode theme is dark. By my understanding, this issue was resolved and the VSCode is supposed to default the matplotlib figures to dark_background when the VSCode theme is default dark.
What am I doing wrong?
I am fairly new to this whole data science and machine learning scene, and up till now I have been using Jupyter Notebook (and sometimes Jupyter Lab) for all my coding needs. However, the code completion in Jupyter Notebook leaves something to be desired, and so began my search for alternatives to Jupyter Notebook.
I recently discovered that VSCode supports the use of Jupyter Notebook natively and after installing python extension, I was able to create new and open previously saved .ipynb files and every thing works great (especially the IntelliSense).
There is, however, one issue which is somewhat a nuisance. My theme for VSCode is default dark, and the figures produced by matplotlib are in light theme.
I know I can use following code to render the figures in dark mode:
from matplotlib import style
style.use('dark_background')
But on GitHub, this issue has already been addressed so that when the VSCode is in dark mode, then the VSCode will automatically default the matplotlib style to dark_background. However I am not experiencing this automation.
Is there some setting that I have failed to configure?
On macOS with VS version 1.63.2 I found that enabling the following setting did the trick:
After some searching I found this solution:
In settings (via ctrl+,) search for
jupyter run startup commands
edit the json to:
"jupyter.runStartupCommands": [
"import matplotlib.pyplot as plt",
"plt.style.use('dark_background')"
]
Then, restart your kernel.
Note, that somehow only using matplotlib.style.use('dark_background') does not yet fully work out, since some part gets overwritten on loading pyplot in the notebook it seems.

Cannot change to a different GUI toolkit: notebook - Warning in Jupyter

I want to use the interactive plots in jupyter, but when switching the backend to notebook, I get the warning:
Warning: Cannot change to a different GUI toolkit: notebook. Using qt5 instead.
This happens on Windows 10, Anaconda 1.8.7, jupyter 5.5.0, python 3.6.5 and matplotlib 2.2.2.
Minimal working example:
import matplotlib.pyplot as plt
%matplotlib notebook
Output:
Warning: Cannot change to a different GUI toolkit: notebook. Using qt5 instead.
I found some question here where the problem is the other way around, but could not find anyone having this problem yet.
In some cases, importing ipympl is mentioned as a solution, but this does not change anything in my case.
Any hints?
As ImportanceOfBeingErnest pointed out in the comments, my problem was related to the backend already being set when jupyter starts. However, as mentioned in this post, the backend needs to be set in the ipython_config.py, not the jupyter_notebook_config.py.
After restarting the notebook server, I can switch between backends as described here.
You must put %matplotlib widget in the very beginning of the Jupyterlab