我已经创建了一个补丁并想将它应用到 Seaborn 中的联合图。当我尝试应用补丁时,它要么将绘图分成两个图形,要么,如果我将 jointplot 函数中的 kind
属性从 kde
更改为其他任何内容,它会抛出错误 inner got multiple values for keyword argument 'ax'
。
当我尝试申请 this solution 时,变量 fg
没有属性 axes
,它不起作用。
在下面的代码中,如果我使用 kind = "scatter"
并省略 ax
,我会得到一个空白输出,然后是 jointpolot。如果我使用 kind = "scatter"
并添加 ax = ax
,则会出现上述错误。如果我使用 kind = "kde"
和 ax = ax
,我会得到以下图像:
我的代码:
import descartes
import fiona
import matplotlib.pyplot as plt
import seaborn as sns
from shapely.geometry import shape
import pandas as pd
import time
#
start_time = time.time()
input_csv = r"C:\path\to\a\csv\with\coordinates.csv"
shapefile = r"C:\path\to\a\fun\shapefile.shp"
df = pd.read_csv(input_csv, delimiter = ",")
df = df[df["Latitude"] > 37.70833]
lat = "Latitude"
lon = "Longitude"
fig = plt.figure()
ax = fig.add_subplot(111, frameon = False)
shp = fiona.open(shapefile)
pol = shp.next()
geom = shape(pol["geometry"])
un_sf = geom.envelope.symmetric_difference(geom)
un_sf_patch = descartes.PolygonPatch(un_sf)
ax.add_patch( un_sf_patch )
my_fig = sns.jointplot(x = lon, y = lat, data = df, color = "grey", kind = "scatter")
end_time = round(time.time() - start_time, 5)
print "Seconds elapsed: {0}".format(end_time)
如何在单个图形中将补丁添加到我的 Seaborn 联合图中?
最佳答案
seaborn jointplot
创建自己的图形以及 3 个轴。
g = sns.jointgrid(..)
g.ax_joint # big axes in the middle
g.ax_marg_y # marginal axes
g.ax_marg_x
在这里,您要将补丁添加到 ax_joint
。
g = sns.jointgrid(..)
g.ax_joint.add_patch( un_sf_patch )
关于python - 向 Seaborn jointploint 添加补丁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52469643/