seaborn

Scatterplot with point colors representing a continuous variable in seaborn FacetGrid

北战南征 提交于 2020-01-20 03:31:04
问题 I am trying to generate multi-panel figure using seaborn in python and I want the color of the points in my multi-panel figure to be specified by a continuous variable. Here's an example of what I am trying to do with the "iris" dataset: import numpy as np import pandas as pd import seaborn as sns import matplotlib as mpl import matplotlib.pyplot as plt iris = sns.load_dataset('iris') g = sns.FacetGrid(iris, col = 'species', hue = 'petal_length', palette = 'seismic') g = g.map(plt.scatter,

jupyter模块导入问题

跟風遠走 提交于 2020-01-18 03:57:22
问题描述 使用 Jupyter 的过程中, import seaborn; 始终报错。 --------------------------------------------------------------------------- ImportError Traceback (most recent call last) <ipython-input-1-c11644355f18> in <module>() 4 import numpy as np 5 import matplotlib.pyplot as plt ----> 6 import seaborn; 7 from sklearn.linear_model import LinearRegression 8 from scipy import stats ImportError: No module named seaborn 解决办法 通过在Jupyter中执行 !which python 和 !which pip 确定 python 和 pip 的版本是对的 /Users/liuwenxue/tensorflow3/bin/python /Users/liuwenxue/tensorflow3/bin/pip 确定安装的 python 版本是对的。而且 pip install seaborn

How to set custom colors on a count plot in seaborn

混江龙づ霸主 提交于 2020-01-16 09:35:50
问题 I have created a set of raincloud plot distributions that follow a specific color scheme (Set2 from seaborn). I wanted to have my countplot match the colors by group listed (example: male and female counts would be green for the diet group, m:f counts would be pink for mod-pa etc). However I'm unable to align the color palette to both the x variable and the hue. It seems countplot will only color based on the hue. Color scheme of raincloud plots Color scheme of bar plot I have tried using set

Seaborn barplot legend labels lose color

若如初见. 提交于 2020-01-15 10:56:28
问题 I have a seaborn boxplot which when I try to use plt.legend("Strings") to change name of labels it loses the colors of the labels. I need to change labels while maintaining the color coding, but I do not know how to do this after searching for an answer. The Hues legend 1-4 corresponds from 1 = Very interested in politics to 4 = not at all interested. I want to change the legend hue labels from 1-4 to how interested they are in politics. My code is: Packages import pandas as pd import numpy

show metrics like kurtosis, skewness on distribution plot using seaborn in python

旧城冷巷雨未停 提交于 2020-01-15 09:28:28
问题 I have the below data: coll_prop_tenure coll_prop_12m coll_prop_6m coll_prop_3m 0.04 0.04 0.06 0.08 0 0 0 0 0 0 0 0 0.06 0.06 0.1 0 0.38 0.38 0.25 0 0.61 0.61 0.66 0.61 0.01 0.01 0.02 0.02 0.1 0.1 0.12 0.16 0.04 0.04 0.04 0.09 0.22 0.22 0.22 0.22 0.72 0.72 0.73 0.72 0.39 0.39 0.45 0.64 I am using distplot from seaborn to plot the distribution as below: ######################## density plot ######################################### f, axes = plt.subplots(2, 2, figsize=(7, 7), sharex=True) sns

Seaborn histogram with bigdata

…衆ロ難τιáo~ 提交于 2020-01-15 09:20:11
问题 I am trying to plot a nice histogram of a big dataset of 3 mln rows (I have 2CPUs/16GB RAM). Even though I provided bins, I never got a plot. Is there more efficient method to plot a histogram? See the code below. df0 = dd.read_csv(filename, sep="|", header=None, dtype=np.str, error_bad_lines=False, usecols=col0, quoting=3, encoding='ISO-8859-1') dfs = df0[df0['DocumentTypeStndCode']=='D'].compute() dfs['Price'] = dfs[pd.to_numeric(dfs['Price'], errors='coerce').notnull()] sns.distplot(dfs[

Add text annotation to seaborn lmplot

可紊 提交于 2020-01-15 06:44:10
问题 I am trying to create seaborn lmplot for a clustering result, data example are shown below: ID CA IP clusters 38 10.3 5.6 1 59 10.4 6.1 0 64 10.0 6.6 1 35 10.6 5.6 1 54 10.6 5.6 1 60 10.2 8.2 1 There are two clusters (cluster 0 and cluster 1), and I want to show the "ID" based on "ID" column on each scatter . Tried the function of adding text as in seaborn regplot but there are errors saying "FacetGrid does not have text function". Codes for seaborn plot: ax = sns.lmplot('CA', 'IP', data=df

Color the shaded area under the curve distribution plot different colors

大兔子大兔子 提交于 2020-01-15 04:34:45
问题 I'm using seaborn's kdeplot to draw the distribution of my data. sns.kdeplot(data['numbers'], shade=True) I want to divide the shaded area under the line into three parts, showing the "high" percentile and the "low" percentile. It would be ideal if I can color the shaded area with three different colors. Any idea how I can go about doing that? I want it to look something like the below where I can decide the cutoff value between the colors. 回答1: So I figured out how to do it. I would retrieve

Apply seaborn heatmap columnwise on pandas dataframe

独自空忆成欢 提交于 2020-01-14 12:17:31
问题 I was trying to use a heatmap form seaborn on a pivoted pandas dataframe like in the hyperlink which works df = pd.DataFrame(np.random.randint(1,100,size = (3,2))) df.columns = ['A','B'] df sns.heatmap(df, annot=True, fmt="d", linewidths=.5,cmap="RdYlGn") Output of code block - Entire Dataframe formatted as single heatmap The output picks 45 as min and 86 as max and color codes the entire dataframe But what i was unable to do was to apply the heatmap column wise i.e. like conditional

Data Availability Chart in Python

徘徊边缘 提交于 2020-01-14 03:39:06
问题 I am wondering if Python has something to plot the data availability of time series with multiple variables. An example is shown below taken from Visavail.js - A Time Data Availability Chart. 回答1: Here's a suggestion using plotly in a Jupyter Notebook: Code: import random import pandas as pd import plotly.express as px from random import choices # random data with a somewhat higher # probability of 1 than 0 to mimic OPs data random.seed(1) vals=[0,1] prob=[0.4, 0.6] choices(vals, prob) data=[