制作条件映射

2024-04-25 09:49:45 发布

您现在位置:Python中文网/ 问答频道 /正文

嗨,我真的希望有人能帮我解决这个问题。你知道吗

我想用Python做条件映射来集成三个变量。1.imd指数2.主要车型3。大房子。你知道吗

图书馆: %matplotlib内联

import seaborn as sns
import pandas as pd
import pysal as ps
import geopandas as gpd
import numpy as np
import matplotlib.pyplot as plt

我做到了:

def map_subset(vals, db, color=None, norm=True):
    '''
    Internal function to pass to `FaceGrid` to build a single map
    ...

    Arguments
    ---------
    vals     : Series
               Values of the subplot to be mapped
    db       : GeoDataFrame
               Table with geometries
    color    : None
    '''
    ax = plt.gca()
    db.plot(color='grey', ax=ax)
    vari = vals.name
    if norm:
        db.reindex(vals.index).plot(column=vari, ax=ax, cmap='Blues', 
linewidth=0., \
                               vmin=db[vari].min(), vmax=db[vari].max())
    else:
        db.reindex(vals.index).plot(column=vari, ax=ax, cmap='Blues', 
linewidth=0.)
    ax.set_axis_off()
    plt.axis('equal')

然后是主要代码:

g = sns.FacetGrid(both, row="Major car", col="Major housetype", \
                  margin_titles=True, size=5)
g.map(map_subset, "imd_score", db='imd_house_car')
plt.tight_layout()
plt.show()

imd\u house\u car是imd\u house和imd\u car的联接表。Python警告:映射\u子集()为参数“db”获取了多个值。请任何人告诉我缺点。你知道吗

非常感谢。你知道吗


Tags: toimportmapdbplotmatplotlibasplt