Visualize the neighborhood sequences within each sequence cluster¶
import numpy as np
import pandas as pd
%matplotlib inline
An example of LA¶
Suppoose we have applied two sequence methods to assess the dissimilarity of neighborhood sequences and obtained two clusterings on neighborhood sequences. These two neighborhood sequences clusterings are stored as two columns in a csv file together with neighborhood types in 1970, 1980, 1990, 2000, and 2010.
We first read the csv file:
df_LA = pd.read_csv("data/LA_sequences.csv", converters={'GEO2010': lambda x: str(x)})
df_LA.head()
GEO2010 | 1970 | 1980 | 1990 | 2000 | 2010 | seqC1 | seqC2 | |
---|---|---|---|---|---|---|---|---|
0 | 06059062641 | 5 | 7 | 5 | 9 | 10 | 4 | 4 |
1 | 06059062643 | 6 | 5 | 6 | 6 | 10 | 5 | 4 |
2 | 06059099251 | 5 | 1 | 1 | 1 | 1 | 2 | 7 |
3 | 06059099305 | 1 | 1 | 1 | 1 | 1 | 1 | 7 |
4 | 06059099306 | 1 | 1 | 1 | 1 | 10 | 2 | 7 |
The two neighborhood sequences clusterings labels are store in “seqC1” and “seqC2”. We can call the index plot function in geosnap
to visualize the compositions of sequences within each cluster:
from geosnap.visualize import indexplot_seq
/Users/weikang/anaconda3/lib/python3.6/site-packages/pyarrow/pandas_compat.py:698: FutureWarning: .labels was deprecated in version 0.24.0. Use .codes instead. labels = getattr(columns, 'labels', None) or [ /Users/weikang/anaconda3/lib/python3.6/site-packages/pyarrow/pandas_compat.py:725: FutureWarning: the 'labels' keyword is deprecated, use 'codes' instead return pd.MultiIndex(levels=new_levels, labels=labels, names=columns.names) /Users/weikang/anaconda3/lib/python3.6/site-packages/pyarrow/pandas_compat.py:742: FutureWarning: .labels was deprecated in version 0.24.0. Use .codes instead. labels, = index.labels
(1) “seqC1”¶
indexplot_seq(df_LA, clustering="seqC1", palette="pastel")
/Users/weikang/Google Drive/python_repos/geosnap/geosnap/analyze/dynamics.py:508: MatplotlibDeprecationWarning: The set_cmap function was deprecated in Matplotlib 3.1 and will be removed in 3.3. Use ScalarMappable.set_cmap instead. colorbar.set_cmap(cluster_cmap) /Users/weikang/Google Drive/python_repos/geosnap/geosnap/analyze/dynamics.py:516: UserWarning: This figure includes Axes that are not compatible with tight_layout, so results might be incorrect. plt.tight_layout()

indexplot_seq(df_LA, clustering="seqC1", palette="pastel", ncols=4)
/Users/weikang/Google Drive/python_repos/geosnap/geosnap/analyze/dynamics.py:508: MatplotlibDeprecationWarning: The set_cmap function was deprecated in Matplotlib 3.1 and will be removed in 3.3. Use ScalarMappable.set_cmap instead. colorbar.set_cmap(cluster_cmap) /Users/weikang/Google Drive/python_repos/geosnap/geosnap/analyze/dynamics.py:516: UserWarning: This figure includes Axes that are not compatible with tight_layout, so results might be incorrect. plt.tight_layout()

indexplot_seq(df_LA, clustering="seqC1", palette="pastel", ncols=2)
/Users/weikang/Google Drive/python_repos/geosnap/geosnap/analyze/dynamics.py:508: MatplotlibDeprecationWarning: The set_cmap function was deprecated in Matplotlib 3.1 and will be removed in 3.3. Use ScalarMappable.set_cmap instead. colorbar.set_cmap(cluster_cmap) /Users/weikang/Google Drive/python_repos/geosnap/geosnap/analyze/dynamics.py:516: UserWarning: This figure includes Axes that are not compatible with tight_layout, so results might be incorrect. plt.tight_layout()

(2) “seqC2”¶
indexplot_seq(df_LA, clustering="seqC2", palette="pastel")
/Users/weikang/Google Drive/python_repos/geosnap/geosnap/analyze/dynamics.py:508: MatplotlibDeprecationWarning: The set_cmap function was deprecated in Matplotlib 3.1 and will be removed in 3.3. Use ScalarMappable.set_cmap instead. colorbar.set_cmap(cluster_cmap) /Users/weikang/Google Drive/python_repos/geosnap/geosnap/analyze/dynamics.py:516: UserWarning: This figure includes Axes that are not compatible with tight_layout, so results might be incorrect. plt.tight_layout()
