seaborn

Seaborn: Arrange multiple Facetgrids

谁都会走 提交于 2021-01-29 14:51:02
问题 I have some trouble understanding seaborns FacetGrids. I have 16 cotegorical columns in my data and I want to use countplot to show the distribution over the values. In addition i have one target variable Y which have to classes. Now I want the calculations for the countplot to be class-dependet. So for each of my 16 input variables I want to have to subplots ( for class 0 and class 1). I can achieve this by (not sure if this is the best solution): for col in df: g = sbn.FacetGrid(df, col="Y"

Ordering y-axis of seaborn boxplot?

浪尽此生 提交于 2021-01-29 14:48:47
问题 I have the following view: but I'd like to have the y-axis here ordered so the num_engagements field is increasing as the y-axis goes up instead of the reverse case here. I've tried playing with the order field in the seaborn options, but if I set order=['num_engagements'] then I just get a blank plot as a result. Any thoughts? 回答1: You need to pass in a list of all the y-axis labels to your order keyword. The following would achieve what you want: sns.boxplot(y='num_engagements', x='channel

Seaborn heatmap is generating additional ticks on colorbar when using log scale

你离开我真会死。 提交于 2021-01-29 11:26:39
问题 I am trying to make a heatmap with logarithmic colorbar. But it keeps generating its own ticks and ticklabels along with the ones I input. I originally posted this to reformat the tick labels from scientific notation to plain but then ran into this problem. import numpy as np import seaborn as sns from matplotlib.colors import LogNorm import matplotlib.ticker as tkr matrix = np.random.rand(10, 10)/0.4 vmax=2 vmin=0.5 cbar_ticks = [0.5, 0.75, 1, 1.33, 2] formatter = tkr.ScalarFormatter

Seaborn factorplot

爷,独闯天下 提交于 2021-01-29 08:31:34
问题 I am trying to create a factor plot but I am not able to change the kind of it from point to bar. How do we do that? The codes used are import numpy as np import matplotlib.pyplot as plt import seaborn as sns %matplotlib inline sns.catplot('Sex',kind="bar",data=titanic_df) 回答1: The seaborn documentation has the exact example you are looking for. Following the documentation, if you run the below lines, it should generate the bar plot shown. import matplotlib.pyplot as plt import seaborn as sns

adding hatches to seaborn heatmap plot

心不动则不痛 提交于 2021-01-29 08:21:22
问题 Is there a way to hatch particular 'cells' in a seaborn heatmap, which e.g. fullfill a condition? I already tried it with masked arrays and matplotlib pcolor, but it turned out that it hatched the wrong cells. import numpy as np import seaborn as sns import matplotlib.pyplot as plt flights = sns.load_dataset("flights") flights = flights.pivot("month", "year", "passengers") zm = np.ma.masked_less(flights.values, 200) x= np.arange(0,12) y= np.arange(0,12) sns.heatmap(flights,linewidth=.1) plt

How to plot multiple seaborn.distplot in a single figure

吃可爱长大的小学妹 提交于 2021-01-29 07:19:25
问题 I want to plot multiple seaborn distplot under a same window, where each plot has the same x and y grid. My attempt is shown below, which does not work. # function to plot the density curve of the 200 Median Stn. MC-losses def make_density(stat_list,color, layer_num): num_subplots = len(stat_list) ncols = 3 nrows = (num_subplots + ncols - 1) // ncols fig, axes = plt.subplots(ncols=ncols, nrows=nrows, figsize=(ncols * 6, nrows * 5)) for i in range(len(stat_list)): # Plot formatting plt.title(

How to add correct labels for Seaborn Confusion Matrix

假如想象 提交于 2021-01-29 05:07:20
问题 I have plotted my data into a confusion matrix using seaborn but I ran into a problem. The problem is that it is only showing numbers from 0 to 11, on both axes, because I have 12 different labels. My code looks as follows: cf_matrix = confusion_matrix(y_test, y_pred) fig, ax = plt.subplots(figsize=(15,10)) sns.heatmap(cf_matrix, linewidths=1, annot=True, ax=ax, fmt='g') Here you can see my confusion matrix: I am getting the confusion matrix as I should. The only problem is the names of the

catplot(kind=“count”) is significantly slower than countplot()

旧巷老猫 提交于 2021-01-29 04:35:00
问题 I am working on a fairly large dataset (~40m rows). I have found that if I call sns.countplot() directly then my visualisation plots really quickly: %%time ax = sns.countplot(x="age_band",data=acme) However if I do the same visualisation using catplot(kind="count") then the speed of execution slows down dramatically: %%time g = sns.catplot(x="age_band",data=acme,kind="count") Is there a reason for such a large performance difference? Is catplot() doing some sort of conversion on my data

Resize subplots using seaborn

依然范特西╮ 提交于 2021-01-29 03:14:51
问题 I have just recently started to use matplotlib and seaborn to plot my graphs. This is the code that I wrote so far count = 1 l=[13,0,47,29,10] plt.figure(figsize=(30,40)) for ww in l: temp_dict = defaultdict(list) entropies = list() for k,v in df.ix[ww].iteritems(): e = 0 for i in v: temp_dict[k].append(float(i)) if not float(i) == 0: e += -1.0*float(i)*log10(float(i)) entropies.append(e) y = entropies x=(range(len(entropies))) slope, intercept, r_value, p_value, std_err = stats.linregress(x

Adding simple error bars to Seaborn factorplot

怎甘沉沦 提交于 2021-01-29 03:07:20
问题 I have a factorplot that I have generated from a summary table, rather than raw data: Using the following code: sns.factorplot(col="followup", y="probability", hue="next intervention", x="age", data=table_flat[table_flat['next intervention']!='none'], facet_kws={'ylim':(0,0.6)}) Plotted here are the mean values from the summary table, but I would also like to plot the credible interval, whose upper and lower bounds are specified in two other columns. The table looks like this: Is there a way,