How can I reduce the contextily source footer at the bottom of a cartopy GeoAxes? - geopandas

I'm attempting to plot a contextily basemap onto one of my cartopy GeoAxes, but the problem is the source footer at the bottom is HUGE. Is there any way to decrease its size? Thanks!
This is how I simply add it to my axes:
import contextily as ctx
ax2=fig.add_subplot(gs01[:,0], projection=ccrs.PlateCarree())
ctx.add_basemap(ax2)

You can set option attribution_size in ctx.add_basemap, for example:-
ctx.add_basemap(ax2, attribution_size=6)

Related

Overlay contour to medical image

I am trying to plot the contour of an image and get it overlaid over the original image but without filling, I would like it to appear as an edge contour instead of a filled contour like the attached picture.
I used this command but the problem is when I used the LabelOverlay function the image contrast changed! while I need to keep the same image intensity, any idea of how to solve it? The code is : sitk_show(SimpleITK.LabelOverlay(imgOriginal1, SimpleITK.LabelContour(imgOriginal2)))
I would encourage you to check out platipy - a software package for which I am a developer and have built some nice tools for visualisation.
Here is an example:
import SimpleITK as sitk
from platipy.imaging import ImageVisualiser
img = sitk.ReadImage("./CT.nii.gz")
mask = sitk.ReadImage("./MASK_LUNGS.nii.gz")
vis = ImageVisualiser(img)
vis.add_contour(mask)
fig = vis.show()
fig.savefig("example.jpeg", dpi=300)
This tool is highly customisable, check out the documentation on Github :-)

Zooming out on pandas table in Jupyter Notebooks

I am attempting to take a screenshot of a correlation table made with pandas in Jupyter Notebooks but since it is very wide I must scroll to the right in order to view the whole table. On a mac it is not possible to scroll left or right while taking a screenshot so I am unable to capture the entire table. Is there anyway to get the entire table (doesn't have to be a screenshot an export of some type would work as well)?
Is the table already shown in markdown? If not, you can try df.to_html(). From there, you can convert it to pdf, see (https://www.npmjs.com/package/markdown-pdf)
Otherwise you can plot the pandas table with matplotlib and remove the axis etc.
import matplotlib.pyplot as plt
import pandas as pd
from pandas.table.plotting import table
ax = plt.subplot(111, frame_on=False) # no visible frame
ax.xaxis.set_visible(False) # hide the x axis
ax.yaxis.set_visible(False) # hide the y axis
table(ax, df) # where df is your data frame
plt.savefig('table.png')

An existing vega-lite map suddenly seems very zoomed-in - what is happening?

I have a map with an older topojson format that once worked with Vega-Lite. Now we only see a purple square in this editor gist.
I've rebuilt the map with the same code but updated topojson in the vega editor and saved as a gist here.
With the new vega release, it seems like I need my topojson files to be formatted differently, with the arcs first, like the mapshaper.org export output. Why is this? It's broken several existing web maps, and took me a few hours to figure out. Seems like I can fix it with a workflow change, but I am curious.
Topojson data follows the left-hand rule for projected data (clockwise orientation for outer rings and counter- clockwise for interior rings), where the data in your topojson file is structured according the right-hand rule (counter-clockwise for outer rings and clockwise for interior rings). The order of your polygons seems negligible, but it defines which part is ‘inside’ and ‘outside’ the polgygons.
You can do two things:
Do not use a geographic projection, but the cartesian-like identity projection.
Force your source data into the right order.
Example for 1:
"projection": {"type": "identity", "reflectY": true},
see Vega Editor
Example for 2:
Use MapShaper or Python to force your data in the right order. Here an example using Python
import topojson as tp
import geopandas as gpd
gdf = gpd.read_file('https://raw.githubusercontent.com/nycehs/NeighborhoodReports/master/visualizations/json/UHF42.topo_old.json')
tp.Topology(gdf).to_json('UHF42.topo_new.json')
see Vega Editor
I wrote a bit about it before for Altair and Python Topojson
https://mattijn.github.io/topojson/example/settings-tuning.html#winding_order
https://altair-viz.github.io/user_guide/data.html#winding-order
And Mike Bostock for D3
https://bl.ocks.org/mbostock/a7bdfeb041e850799a8d3dce4d8c50c8

How to enlarge/resize topojson map file with Vincent

I am trying to use Vincent to create state zip code maps. I'm using the State files posted on github by #jlev. However, when I try to display them in iPython notebook or even when I render the same vega object on an HTML page, the map shows up very small with a lot of white space around it. I am using the equirectangular projection. When I try to increase the scale in iPython notebook, the map gets only slightly larger, but the whitespace surrounding the map gets exponentially larger. I can import them into mapshaper.org and they look fine, so I don't think there are any issues with the topo.json files. Looking for some guidance on resizing these in Vincent. The most luck I've had with this is by changing the scale on the topo.json file itself, but I can only increase these so much before the map gets distorted with a lot of extra lines.
Here is my python code:
zip_topo = r'topo_files/Maryland.topo.json'
geo_data = [{'name': 'Maryland',
'url': zip_topo,
'feature': 'Maryland.geo'}]
vis = vincent.Map(geo_data=geo_data,scale=8000,projection='equirectangular')
vis.display()

Add an (SVG-) image to an existing graph in R

I'd like to an an image (ideally an SVG) as an inset to an existing graph in R and put a black border around the image.
Is that possible with base-functions in R? Do I need packages for that?
Maybe the grImport package is what you are looking for ? It only seems to allow to import Posctscript files, however.
You can find two vignettes files on the package web page, which should help you learn how to use it.
Convert your SVG to PostScript, then you can do all this good stuff:
http://www.stat.auckland.ac.nz/~paul/Talks/import.pdf
If there's an easier way to convert from SVG to the RGML format mentioned there, that would be a better option.

Resources