cartopy: higher resolution for great circle distance line

2024/10/7 14:27:05

I am trying to plot a great circle distance between two points. I have found an in the cartopy docs (introductory_examples/01.great_circle.html):

import matplotlib.pyplot as plt
import cartopy.crs as ccrsax = plt.axes(projection=ccrs.Robinson())ax.set_global()ax.coastlines()plt.plot([-0.08, 132], [51.53, 43.17], color='red',      transform=ccrs.Geodetic())
plt.plot([-0.08, 132], [51.53, 43.17], color='blue', transform=ccrs.PlateCarree())plt.show()

which makes the following image:

great circle example

The thing is, in my own work, the two points are much closer together, and in a different projection (though I think that isn't important here). If I change this code to be a line in a smaller area, like so:

import matplotlib.pyplot as plt
import cartopy.crs as ccrsax = plt.axes(projection=ccrs.Robinson())ax.set_extent([-5, 55, 40, 55])ax.coastlines()plt.plot([-0.08, 50], [51.53, 43.17], color='red',      transform=ccrs.Geodetic())
plt.plot([-0.08, 50], [51.53, 43.17], color='blue', transform=ccrs.PlateCarree())plt.show()

This makes the following image: shorter line

The red great circle line in this case looks crappy and looks like it is due to being too low resolution. How do I increase the number of points making up the great circle line?

Answer

This problem is due to the hard-coded threshold in the projection. Currently this is not a user controllable parameter, but you can work around that by defining your own sub-class:

class LowerThresholdRobinson(ccrs.Robinson):@propertydef threshold(self):return 1e3

If you use LowerThresholdRobinson() instead of ccrs.Robinson() when defining the axes this should eliminate the problem.

https://en.xdnf.cn/q/70239.html

Related Q&A

Python Flask date update real-time

I am building a web app with Python Flask with JavaScript. I am a beginner of Javascript.The process I do now:In Flask Python code, 1. I get data by scrapping the web (numeric data that updates every m…

How do I force pip to install from the last commit of a branch in a repo?

I want pip to install from the latest commit on a master branch of my github repository. I tried many options mentioned here on StackOverflow, none helped. For instance, that does not work:pip install …

Emacs: pass arguments to inferior Python shell during buffer evaluation

recently I started using Emacs as a Python IDE, and it not quite intuitive... The problem I am struggling with right now is how to pass command line arguments to the inferior python shell when the buff…

How to edit a wheel package (.whl)?

I have a python wheel package, when extracted I find some python code, Id like to edit this code and re-generate the same .whl package again and test it to see the edits .. How do I do that?

Choosing order of bars in Bokeh bar chart

As part of trying to learn to use Bokeh I am trying to make a simple bar chart. I am passing the labels in a certain order (days of the week) and Bokeh seems to be sorting them alphabetically. How ca…

buildout - using different python version

i have set up buildout project (django to be specific) that has to run in old machine, it works fine in my local system with python 2.7. In production server it runs python 2.5 and i want to configure…

Receive an error from lingnutls/Hogweed when importing CV2

Ive never seen an error like this and dont know where to start. I installed opencv with conda install opencvand am running Ubuntu Linux 18.04 using a conda environment named fpn. How should I even appr…

Understanding django admin readonly_fields

I created some code to differentiate between two usergroups in Django admin, resulting in showing all fields readonly or only some of them, which are set directly in the ModelAdmin class.At first here …

The seaborn styles shipped by Matplotlib are deprecated since 3.6

The seaborn styles shipped by Matplotlib are deprecated since 3.6, as they no longer correspond to the styles shipped by seaborn. However, they will remain available as seaborn-v0_8-<style>. Alte…

Python: Can the pydoc module output HTML docs with relative paths?

I am using the pydoc module to output documentation for some types which I have defined with the C API. The types I want to document dont exist until the interpreter has been embedded inside my C progr…