seaborn

incorrect Colorbar for log values in scatter plot

两盒软妹~` 提交于 2020-01-13 19:43:25
问题 I want to use a scatter plot to describe the relationship between X, Y and Z. Z is p-value so it is better to denote it as log values. Following the instructions here, I can plot a logarithmic scatter plot, but the color bar seems wrong. The color bar is almost totally blue, but there should be some red! Below is the figure and my codes. import matplotlib import matplotlib.pyplot as plt import seaborn as sns from matplotlib.colors import LogNorm fig = plt.figure() ax1 = fig.add_subplot(1,1,1)

Box Plot of a many Pandas Dataframes

自作多情 提交于 2020-01-12 08:49:08
问题 I have three dataframes containing 17 sets of data with groups A, B, and C. A shown in the following code snippet import pandas as pd import numpy as np data1 = pd.DataFrame(np.random.rand(17,3), columns=['A','B','C']) data2 = pd.DataFrame(np.random.rand(17,3)+0.2, columns=['A','B','C']) data3 = pd.DataFrame(np.random.rand(17,3)+0.4, columns=['A','B','C']) I would like to plot a box plot to compare the three groups as shown in the figure below I am trying make the plot using seaborn's box

additional row colors in seaborn cluster map

江枫思渺然 提交于 2020-01-12 03:42:06
问题 I am currently generating clustermaps in seaborn and labeling the row colors as below. matrix = pd.DataFrame(np.random.random_integers(0,1, size=(50,4))) labels = np.random.random_integers(0,5, size=50) lut = dict(zip(set(labels), sns.hls_palette(len(set(labels)), l=0.5, s=0.8))) row_colors = pd.DataFrame(labels)[0].map(lut) g=sns.clustermap(matrix, col_cluster=False, linewidths=0.1, cmap='coolwarm', row_colors=row_colors) plt.show() I have a second annotation column similar to the labels

Heatmap with circles indicating size of population

梦想的初衷 提交于 2020-01-11 09:34:07
问题 Hi I would like to produce a heatmap in Python, similar to the one shown, where the size of the circle indicates the size of the sample in that cell. I looked in seaborn's gallery and couldn't find anything, and I don't think I can do this with matplotlib. 回答1: It's the inverse. While matplotlib can do pretty much everything, seaborn only provides a small subset of options. So using matplotlib, you can plot a PatchCollection of circles as shown below. Note: You could equally use a scatter

how to change the order of factor plot in seaborn

雨燕双飞 提交于 2020-01-11 08:11:30
问题 My data looks like this: m=pd.DataFrame({'model':['1','1','2','2','13','13'],'rate':randn(6)},index=['0', '0','1','1','2','2']) I want to have the x-axis of factor plot ordered in [1,2,13] but the default is [1,13,2]. Does anyone know how to change it? Update : I think I have figured it out in the following way, but maybe there is a better way by using an index to do that? sns.factorplot('model','rate',data=m,kind="bar",x_order=['1','2','13']) 回答1: Your update to the post shows the correct

AttributeError: Unknown property legend in seaborn

╄→гoц情女王★ 提交于 2020-01-11 08:06:08
问题 The seaborn stripplot has a function which allows hue . Using the example from https://stanford.edu/~mwaskom/software/seaborn/generated/seaborn.stripplot.html import seaborn as sns sns.set_style("whitegrid") tips = sns.load_dataset("tips") ax = sns.stripplot(x=tips["total_bill"]) ax = sns.stripplot(x="sex", y="total_bill", hue="day", data=tips, jitter=True) In this case, the legend is quite small, showing a different hue for each day. However, I would like to remove the legend. Normally, one

Hexbin plot in PairGrid with Seaborn

好久不见. 提交于 2020-01-11 06:59:51
问题 I am trying to get a hexbin plot in a Seaborn Grid. I have the following code, # Works in Jupyter with Python 2 Kernel. %matplotlib inline import seaborn as sns import matplotlib as mpl import matplotlib.pyplot as plt tips = sns.load_dataset("tips") # Borrowed from http://stackoverflow.com/a/31385996/4099925 def hexbin(x, y, color, **kwargs): cmap = sns.light_palette(color, as_cmap=True) plt.hexbin(x, y, gridsize=15, cmap=cmap, extent=[min(x), max(x), min(y), max(y)], **kwargs) g = sns

change line style in seaborn facet grid

我们两清 提交于 2020-01-11 06:43:29
问题 I have a data set like this import numpy as np; np.random.seed(3) import pandas as pd import seaborn.apionly as sns import matplotlib.pyplot as plt def get_data(n=266, s=[5,13]): val = np.c_[np.random.poisson(lam=s[0], size=n), np.random.poisson(lam=s[1], size=n)].T.flatten() comp = [s[0]]*n + [s[1]]*n ov = np.random.choice(list("ABC"), size=2*n) return pd.DataFrame({"val":val, "overlap":ov, "comp":comp}) data1 = get_data(s=[9,11]) data2 = get_data(s=[9,11]) data3 = get_data(s=[9,11])

Python数据可视化库-----Seaborn(唐宇迪机器学习笔记)

偶尔善良 提交于 2020-01-10 17:23:25
简介 什么是Seaborn Seaborn 是基于matplotlib的图形可视化python包。它提供了一种高度交互式界面,便于用户能够做出各种有吸引力的统计图表。 Seaborn 是在matplotlib的基础上进行了更高级的API封装,从而使得作图更加容易,在大多数情况下使用seaborn能做出很具有吸引力的图,而使用matplotlib就能制作具有更多特色的图。应该把 Seaborn 视为matplotlib的补充,而不是替代物。同时它能高度兼容numpy与pandas数据结构以及scipy与statsmodels等统计模式。 seaborn 0.9 中文文档 import seaborn as sns import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt def sinplot(flip=1): x=np.linspace(0,14,100)#在区间0到14上找100个点 for i in range(1,7):#画六条线 plt.plot(x,np.sin(x+i*.5)*(7-i)*flip) plt.show() sinplot() 使用seaborn默认风格 sns.set() import seaborn as sns import numpy as np

Stop x-axis labels from shrinking the plot in Matplotlib?

南笙酒味 提交于 2020-01-06 07:59:46
问题 I'm trying to make a bar graph with the following code: import pandas as pd import matplotlib.pyplot as plt import seaborn as sns test = {'names':['a','b','abcdefghijklmnopqrstuvwxyz123456789012345678901234567890'], 'values':[1,2,3]} df = pd.DataFrame(test) plt.rcParams['figure.autolayout'] = False ax = sns.barplot(x='names', y='values', data=df) ax.set_xticklabels(ax.get_xticklabels(), rotation=90) plt.show() But I get the following error because the long value in 'names' as a label on the x