Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 更改FaceGrid上的x轴或设置填充的限制_Python_Python 3.x_Matplotlib_Seaborn - Fatal编程技术网

Python 更改FaceGrid上的x轴或设置填充的限制

Python 更改FaceGrid上的x轴或设置填充的限制,python,python-3.x,matplotlib,seaborn,Python,Python 3.x,Matplotlib,Seaborn,我复制了这本书,并根据我的需要采用了它。我已经包括了工作脚本和一些要测试的示例数据 图片: 我的一些数据的y值等于0.0。我想在我的情节中强调这一点。我不确定可以更改绘图的哪个部分,即填充之间的部分,或仅更改每个x轴,例如删除“aandeel”==0.0位置上的贴图颜色 有没有办法去掉这里的颜色?是否可以删除x轴/将宽度设置为0/将颜色更改为其他颜色 示例数据(csv): 将熊猫作为pd导入 从matplotlib导入pyplot作为plt 导入seaborn作为sns 将numpy作为np导

我复制了这本书,并根据我的需要采用了它。我已经包括了工作脚本和一些要测试的示例数据

图片:

我的一些数据的y值等于0.0。我想在我的情节中强调这一点。我不确定可以更改绘图的哪个部分,即
填充
之间的部分,或仅更改每个x轴,例如删除
“aandeel”==0.0
位置上的贴图颜色

有没有办法去掉这里的颜色?是否可以删除x轴/将宽度设置为0/将颜色更改为其他颜色

示例数据(csv):

将熊猫作为pd导入
从matplotlib导入pyplot作为plt
导入seaborn作为sns
将numpy作为np导入
set(style=“whitegrid”,rc={“axes.facecolor”:(0,0,0,0)})
data=pd.read_csv('stats_together_data.csv',分隔符=';'))
df=数据
#初始化FacetGrid对象
pal=sns.调色板(“Set2”)
g=sns.FacetGrid(df,row=“process”,hue=“process”,aspect=10,height=0.6,pal=pal)
#分几步绘制密度图
g、 地图(sns.lineplot,“区域”,“安德尔”,clip_on=False,alpha=1,lw=1.5)
g、 地图(plt.fill_介于“区域”、“安代尔”之间,插值=真)
g、 地图(sns.lineplot,“region”,“aandeel”,clip_on=False,color=“w”,lw=2)
g、 映射(plt.axhline,y=0,lw=1,clip\u on=False)
#定义并使用一个简单的函数在坐标轴中标记绘图
def标签(x、颜色、标签):
ax=plt.gca()
ax.文本(0.2,标签,fontwweight=“bold”,颜色=颜色,
ha=“left”,va=“center”,transform=ax.transAxes)
g、 地图(标签“区域”)
#将子批次设置为重叠
g、 图子批次调整(hspace=-.25)
#删除与重叠不协调的轴细节
g、 设置标题(“”)
g、 集合(yticks=[])
g、 集合(xticks=df.region[0::1])
g、 鄙视(底部=正确,左侧=正确)
plt.show()

首先,我将用NaN替换0.0值。但这还不够,因为问题的很大一部分是添加水平线以替换底部脊椎,这隐藏了曲线在不同点停止的事实。如果您删除这些,那么您将得到:

就我个人而言,我并没有太多的发现剔白线,这使得左侧和右侧的狭窄区域非常薄。我倾向于删除它们:

完整代码:

import pandas as pd
from matplotlib import pyplot as plt
import seaborn as sns
import numpy as np


sns.set(style="whitegrid", rc={"axes.facecolor": (0, 0, 0, 0)})
df = pd.read_csv('https://gist.githubusercontent.com/willemvanopstal/c2892e68d6eb94194acd371e49d949bd/raw/642c4261198f0cacdf32aad21aebca5953c6cd75/stats_together_data.csv', delimiter=';')
df.loc[df["aandeel"]==0,"aandeel"]=np.nan

# Initialize the FacetGrid object
pal = sns.color_palette("Set2")
g = sns.FacetGrid(df, row="process", hue="process", aspect=10, height=0.6, palette=pal)

# Draw the densities in a few steps
g.map(sns.lineplot, "region", "aandeel", clip_on=False, alpha=1, lw=1.5)
g.map(plt.fill_between, "region", "aandeel", interpolate=True)
#g.map(sns.lineplot, "region", "aandeel", clip_on=False, color="w", lw=2)


# Define and use a simple function to label the plot in axes coordinates
def label(x, color, label):
    ax = plt.gca()
    ax.text(0, .2, label, fontweight="bold", color=color,
            ha="left", va="center", transform=ax.transAxes)


g.map(label, "region")

# Set the subplots to overlap
g.fig.subplots_adjust(hspace=-.25)

# Remove axes details that don't play well with overlap
g.set_titles("")
g.set(yticks=[])
g.set(xticks=df.region[0::1])
g.despine(bottom=True, left=True)

plt.show()