How can I add basemaps to a seaborn jointplot? - seaborn

Can someone guide me on how best to add a background map to two seaborn jointplots I created?
To give context, I am currently analyzing a dataset from Austin Police Dept's Crime Reports database. What I am attempting to do is visualize the density of murders and capital murders in Austin, TX. The dataset extends from the beginning of 2003 to the present.
The notebook can be located at: https://github.com/rgrantham82/Hate_Crimes_Analysis/blob/master/Austin%20Crimes%20Report%20Analysis.ipynb
So far, I visualized both data frames using the seaborn jointplot method, using latitude and longitude.
I BELIEVE this is a good method to plot the density of murders judging by the dataset but if someone has a better idea, I am open to instruction on that as well.
So, if it is even possible, how do I add a basemap to both plots?
So far, I attempted the contextily method and the geopandas method. Admittedly, this is my first attempt (outside of DataCamp class) using either method. As of to date, I am unsuccessful with both.
The contextily addbasemap() method did not produce a map (I guess it does not have one for the Austin area?). And also with the geopandas method I could not get it to work in producing a viable basemap either. I seem to be simply swamped by it.
Murders Plot
Capital Murders Plot

Related

Convert point cloud to spline path

Trying to convert a .csv file which is a point cloud plot but in a sequential type plot..it has all three coordinates and a date time stamp/point..
What I’m trying to do is connect the dots and create a spline for other objects to attach…
Any help would be appreciated..
Was trying to follow the python script on another sub chat..
Fit Curve-Spline to 3D Point Cloud
Was trying this in cinema4D but it doesn’t seemingly handle this level of work..this might be for python patch in blender…
But also mathlab or maple would be a good alternative if anyone out there can help, let me know…

FacetGrid Seaborn taking long time to plot

I have a major concern regarding why in the world the above code:
sns.FacetGrid(iris , row='petal_length' , col='petal_width');
This statement is taking around 10 minutes to execute and I get a single large extremely large white grid.
Why is this happening please help me removing this behavior of the code.
If you are using Jupyter notebook you need to put "%matplotlib inline" in your code after importing matplotlib.pyplot and seaborn library. It allows jupyter notebook to see the plots and diagram that you are trying to create.
I also got stuck in my NLP project then I remembered I forgot this statement in my code.
Hope it helps.

geopandas projection problems

I'm handling shp files now and I encountered problems with the projections.
Let me give you my code below.
import pandas as pd
import geopandas as gpd
from geopandas import GeoSeries, GeoDataFrame
import os
Aelly = gpd.read_file(r'C:\Users\Hyun Mo\Downloads\조인 (1)\after_join.shp', encoding = 'utf-8')
base_map = gpd.read_file(r'C:\Users\Hyun Mo\Downloads\11000 (3)\TL_SCCO_SIG.shp', encoding = 'ANSI')
Aelly_to_crs = Aelly.to_crs(base_map.crs)
Aelly_to_crs.plot(ax=base_map.plot())
And here is my data construction
print(base_map.head())
print(Aelly.head())
When I executed print(base_map.crs), print(Aelly_to_crs.crs), I got the results like below.
Aelly_to_crs.plot(ax=base_map.plot())
The above picture is the result of executing Aelly.plot(ax=base_map.plot())
And you can see that the two pictures don't match each other.
How can I solve this problems??
-----------edit
My desired output is below picture.
Here are my data links:
http://blog.naver.com/khm2963/220929301892
below pictures are procedure for downloading my flie
From the data that you have printed it looks like everything is working as it should! The coordinates between the shapefiles are very different, but crs is the same, so the plot totally makes sense.
GeoPandas isn't able to tell you whether the data and number make sense in a real world. You gave it two shapefiles with well defined projection (EPSG: 32652) and with hardcoded coordinates and GeoPandas is happy with that.
If you know that in reality both shapefiles represent the same area, then you are the one that has to realize that datasource is somehow corrupt. I think that one of the shapefiles accidentally got a different crs definition as a metadata (imagine it as a wrong text encoding, for instance).
The easiest way to figure that out and correct it is by using ArcGIS or QGIS software, where you can play with different projections in order to figure out, what the correct projection was. Then you can save the shapefile with new projection metadata and the rest will work out of the box.

Extend data to extent of graph

I have time-sensitive data that ranges from now until 7 days from now with hourly resolution ~220 values. I was able to get them to plot following Mike Bostock's demo here: http://bost.ocks.org/mike/cubism/intro/demo-stocks.html
but I can't seem to find how to extend the timescales and data to span across the entire display. I was looking for an extent argument or xrange or width, but I haven't had any luck. I'm sure the answer is trivial, but I can't seem to find it.
var context = cubism.context()
.step(3600000) // <-- this changes the time resolution
.size(1280) // <-- this changes the width
.stop();
Also, d3.time.scale.domain seems to be undefined in d3.v3.min.js.
Here's the fiddle that shows you what the code looks like (because it's calling d3.csv I wasn't sure how to get it completely working in the fiddle...so I included the csv file below the javascript.) : http://jsfiddle.net/oay7tvq0/
I think that cubism uses a single pixel for each time slice, so if you've only got 220 timesteps only 220 pixels are needed. Check the documentation to be sure. If I'm correct then you'll either have to be creative with your timeseries and extend the timestep (by repeating adjacent records) or perhaps d3 (or one of the various libraries built on it) would better suit your purposes. – user1614080
This I'm sure is the answer...

Cursors for data selection in matplotlib

I am trying to get user input from matplotlib XY plot. The plot contains multiple datasets and I need get from user selection of which dataset to use and the range. I need this to fit model to right dataset and range.
Therefore I need two indicators, which would be "attached" to specific dataset, per user choosing. I need to get from them both the dataset info and the range info.
Somehow in line with what commercial plotting packages (Igor Pro, Kaleidagraph, Sigmaplot...) provide as "cursors" and similarly named widgets for control of their fitting interface, which is what I am trying to reproduce.
I have checked various examples with rangeselector and other methods I was able to Google on the web, but none I was able to find seems to be able to provide what I need.
Would anyone have any pointers to where to look or what to start with, please?
You might want to look at this example: http://matplotlib.sourceforge.net/examples/pylab_examples/ginput_manual_clabel.html
The interesting functions are ginput, waitforbuttonpress.

Resources