pretty easy if you're using matplotlib & seaborn: import matplotlib.pyplot as plt import seaborn as sns x = range(10) y = range(10) plt.bar(x,y,color= sns.color_palette("BuGn_r", len(x))) plt.show() just pass the length of the x-array as the 2nd parameter of color_palette() ...

python,matplotlib,plot,seaborn,roc

Since seaborn also uses matplotlib to do its plotting you can easily combine the two. If you only what to adopt the styling of seaborn the set_style function should get you started: import matplotlib.pyplot as plt import numpy as np import seaborn as sns sns.set_style("darkgrid") plt.plot(np.cumsum(np.random.randn(1000,1))) plt.show() Result: ...

The violinplot API doesn't play nicely with FacetGrid, but it can be fixed after plotting: g = sns.FacetGrid(teacherValueFinal3, row='Grade Level', col='Course',margin_titles=True) g.map(sns.violinplot, '2013-2014 Assessment Score', 'Gender', color="RdBu") g.set_axis_labels('Gender', '2013-2014 Assessment Score') ...

python,matplotlib,pandas,seaborn

For a more precise answer related to OP's question (with Pandas): import pandas as pd import numpy as np import matplotlib.pyplot as plt data = pd.DataFrame({ "A":np.random.normal(0.8,0.2,20), "B":np.random.normal(0.8,0.1,20), "C":np.random.normal(0.9,0.1,20)} ) data.boxplot() for i,d in enumerate(data): y = data[d] x = np.random.normal(i+1, 0.04, len(y)) plt.plot(x, y, mfc = ["orange","blue","yellow"][i], mec='k', ms=7,...

python,matplotlib,monkeypatching,seaborn

Seaborn does not change the behavior of matplotlib functions in the way you describe. Matplotlib exposes a number of options for customization that take effect by changing the default values of various plot parameters. When seaborn is imported, it runs some code that uses this functionality to change the global...

python,matplotlib,pandas,ipython-notebook,seaborn

barplot isn't using errorbar under the hood, it's just drawing lines in the interval of the CI, so there's no way to add caps. The errorbar width itself is just a scaled factor of the lines.linewidth rc parameter, so you can set that temporarily to control it: with mpl.rc_context("lines.linewidth": 1}):...

python,matplotlib,plot,seaborn

This will work too: fig, ax = plt.subplots() ax = sns.barplot(data = data, x = 'var1', color = '#007b7f') plt.setp(ax.patches, linewidth=0) ...

Another approach would be import seaborn as sns import matplotlib.pyplot as plt tips = sns.load_dataset("tips") points = plt.scatter(tips["total_bill"], tips["tip"], c=tips["size"], s=75, cmap="BuGn") plt.colorbar(points) sns.regplot("total_bill", "tip", data=tips, scatter=False, color=".1") ...

python,python-2.7,pandas,matplotlib,seaborn

Plotting a dataframe in pandas is generally all about reshaping the table so that the individual lines you want are in separate columns, and the x-values are in the index. Some of these reshape operations are a bit ugly, but you can do: df = pd.read_clipboard() plot_table = pd.melt(df.reset_index(), id_vars=['index',...

The other answer is (close to) the right solution, but it might be helpful to understand why this is happening. sns.set_palette and using sns.color_palette in a with statement control the matplotlib color cycle, (mpl.rcParams["axes.color_cycle"]), which is used to style plot elements when using plt.plot. In contrast,imshow has a default colormap,...

1) what you are looking for is most probably some combination of get_yticks() and set_yticks: plt.yticks(fig.get_yticks(), fig.get_yticks() * 100) plt.ylabel('Distribution [%]', fontsize=16) Note: as mwaskom is commenting times 10000 and a % sign is mathematically incorrect. 2) you can specify where you want your ticks via the xticks function. Then...

python,pandas,duplicates,dataframes,seaborn

drop_duplicates does not work on the index, but on the values in the dataframe! (so it looks for duplicate rows, not duplicate indices). But you also have the same function on the index (see doc): df.index.drop_duplicates() With the resulting index, you can reindex. Another option is to add the index...

As you note, factorplot provides an easier interface to using pointplot and FacetGrid together. The reason the legend and dodging doesn't work the original way you're doing it is that setting hue in FacetGrid and setting it in pointplot are different. When you call pointplot without a hue variable, it...

python,matplotlib,heatmap,seaborn

There are two options: First, heatmap is an Axes level figure, so you could set up a main large main heatmap axes for the correlation matrix and flank it with heatmaps that you then pass class colors to yourself. This will be a little bit of work, but gives you...

python,osx,numpy,matplotlib,seaborn

I'm using Mac OS X 10.9.5, python 2.7.9, matplotlib 1.4.3, and seaborn 0.5.1. I was able to reproduce the error. By default I am using the macosx backend for matplotlib. Your code works if I change the backend to qt4agg (requires PyQt4), tkagg or webagg. Here's the script that worked...

python,matplotlib,plot,seaborn

You need to: Extract the data of the kde line Integrate it to calculate the cumulative distribution function (CDF) Find the value that makes CDF equal 1/2, that is the median import numpy as np import scipy import seaborn as sns import matplotlib.pyplot as plt sns.set_palette("hls", 1) data = np.random.randn(30)...

The sub-axes are in there: import numpy as np, pandas as pd; np.random.seed(0) import seaborn as sns#; sns.set(style="white", color_codes=True) tips = sns.load_dataset("tips") g = sns.jointplot(x="total_bill", y="tip", data=tips, kind='reg') regline = g.ax_joint.get_lines()[0] # NOTE: [0] reliable # iff you haven't plotted any other lines regline.set_color('red') regline.set_zorder('5') sns.plt.show() ...

matplotlib,pandas,dataframes,boxplot,seaborn

A general solution for the boxplot for the entire dataframe, which should work for both seaborn and pandas as their are all matplotlib based under the hood, I will use pandas plot as the example, assuming import matplotlib.pyplot as plt already in place. As you have already have the ax,...

python,pandas,data,annotations,seaborn

You can use the aggfunc keyword passing in a dict: aggfunc : function, default numpy.mean, or list of functions If list of functions passed, the resulting pivot table will have hierarchical columns whose top level are the function names (inferred from the function objects themselves) sns.heatmap(df3.pivot_table(index='Place', columns='Name', values='00:00:00',aggfunc={'00:00:00':np.sum}), annot=True, fmt='.1f')...

python,matplotlib,statsmodels,seaborn

As I mention in my comments, there are two ways I would think about doing this. The first is to define a function that does the fit and then plots and pass it to FacetGrid.map: import pandas as pd import seaborn as sns tips = sns.load_dataset("tips") def plot_good_tip(day, total_bill, **kws):...

You can declare fig, ax pair via plt.subplots() first, then set proper size on that figure, and ask sns.regplot to plot on that ax import numpy as np import seaborn as sns import matplotlib.pyplot as plt # some artificial data data = np.random.multivariate_normal([0,0], [[1,-0.5],[-0.5,1]], size=100) # plot sns.set_style('ticks') fig, ax...

matplotlib,boxplot,seaborn,violin-plot

As discussed in the release notes there have been some changes to the API for categorical plots. In your case, you just need to explicitly pass your list (tuple, technically) of arrays to the data parameter: sns.boxplot(data=x) ...

It looks like this issue arises here - from the docs searborn.factorplot hue : string, optional Variable name in data for splitting the plot by color. In the case of ``kind=”bar”, this also influences the placement on the x axis. So, since seaborn uses matplotlib, you can do it like...

python,heatmap,colorbar,seaborn

Once you call heatmap the colorbar axes will get a reference at the axes attribute of the figure object. So you could either set up the figure ahead of time or get a reference to it after plotting with plt.gcf and then pull the colorbar axes object out that way:...

Just turn the yticklabels back to visible and you are good to go, in the desired subplot: import seaborn as sns iris = sns.load_dataset("iris") x_vars = ['sepal_length', 'sepal_width', 'petal_length'] y_vars = ['petal_width'] pp = sns.pairplot(data=iris, x_vars=x_vars, y_vars=y_vars) _ = plt.setp(pp.axes[0,1].get_yticklabels(), visible=True) #changing the 2nd plot _ = ... here is...

python,matplotlib,seaborn,python-ggplot

The first part of your question can be done using colorbar and specifying the colours to be the Cluster array. I have vaguely understood the second part of your question, but I believe this is what you are looking for. import numpy as np import matplotlib.pyplot as plt x =...

python,pandas,matplotlib,plot,seaborn

You could do something like import seaborn as sns import matplotlib.pyplot as plt from scipy.stats import sem tips = sns.load_dataset("tips") tip_sumstats = (tips.groupby(["day", "sex", "smoker"]) .total_bill .agg(["mean", sem]) .reset_index()) def errplot(x, y, yerr, **kwargs): ax = plt.gca() data = kwargs.pop("data") data.plot(x=x, y=y, yerr=yerr, kind="bar", ax=ax, **kwargs) g = sns.FacetGrid(tip_sumstats, col="sex",...

python-3.x,pandas,matplotlib,seaborn

import pandas as pd import numpy as np import matplotlib.pyplot as plt df = pd.read_csv('/home/Jian/Downloads/real_data.csv') # processing # ========================== fig, ax = plt.subplots() ax.set_ylim([0, 1.2]) count = 0 def func(group): group.sort('value', inplace=True) x = np.linspace(0, 1, len(group)) global ax, count if count > 0: ax.plot(x, group.value, label=group.groups.values[0]) count += 1...

You could use JointGrid directly: from scipy import stats g = sns.JointGrid(x, y, ratio=100) g.plot_joint(sns.regplot) g.annotate(stats.pearsonr) g.ax_marg_x.set_axis_off() g.ax_marg_y.set_axis_off() ...

That works: import seaborn as sns import numpy as np import matplotlib.pyplot as plt points = np.random.multivariate_normal([0, 0], [[1, 2], [2, 20]], size=1000) plt.plot([-3, 3],[0,60]) ax = sns.kdeplot(points, shade=True) ax.collections[0].set_alpha(0) plt.show() ...

The plot looks a bit strange. :-) Anyway, the key steps are first set background color to white via sns.set(style="white"), and then plot heapmap with mask parameter to remove those unwanted values. # your data # ============================================================== df Code Value 0 2 4 1 5 6 2 7 1 3...

You either need to change either the axes.axisbelow rc parameter or the zorder of the contourf plot. So you could do sns.set(context="notebook", style="whitegrid", rc={"axes.axisbelow": False}) When you set up the style or plt.contourf(x, y, Z, levels=levels, zorder=0) When you draw the plot....

python,matplotlib,pandas,seaborn

An easy trick might be to invert the y axis of your plot, rather than futzing with the data: s = pd.Series(np.random.choice(list(string.uppercase), 1000)) counts = s.value_counts() ax = counts.iloc[:10].plot(kind="barh") ax.invert_yaxis() Seaborn barplot doesn't currently support horizontally oriented bars, but if you want to control the order the bars appear in...

python,pandas,visualization,seaborn

This is an issue with the new pd.Categorical type in seaborn, which is currently not supported, but is slated for addition in version 0.6.0. See this github issue: https://github.com/mwaskom/seaborn/issues/361

mwaskom had the solution; posting here for completeness - just had to change the following line to: g = sns.FacetGrid(mapping, col=options.facetCol, row=options.facetRow, col_order=sorted(cols), hue=options.group, sharex=False) ...

You'll need to set the markeredgewidth or mew parameter to a positive number.

I'm answering my own question to post the details and explanation of the solution I used, because mwaskom's suggestion required a tweak. Using with reversed(sns.color_palette('Blues_d', n_colors=n_plots)): throws AttributeError: __exit__, I believe because the with statement requires an object with __enter__ and __exit__ methods, which the reversed iterator doesn't satisfy. If...

I couldn't get the example to work with the data you provided, so I'll use one of the example datasets to demonstrate: import seaborn as sns tips = sns.load_dataset("tips") We'll make a plot with sex in the columns, smoker in the rows, using day as the x variable for the...

Just pass a list of colors. Something like values = np.array([2,5,3,6,4,7,1]) idx = np.array(list('abcdefg')) clrs = ['grey' if (x < max(values)) else 'red' for x in values ] sb.barplot(x=idx, y=values, color=clrs) ...

You can do this by overplotting a Rectangle patch on the cell that you would want to highlight. Using the example plot from the seaborn docs import seaborn as sns import matplotlib.pyplot as plt sns.set() flights = sns.load_dataset("flights") flights = flights.pivot("month", "year", "passengers") g = sns.clustermap(flights) We can highlight a...

This seems to be an issue with the MacOSX backend. It is tracked at matplotlib's issue tracker, but a fix apparently needs major rewriting and is not finished yet. (I guess related to this issue). In the meantime switching the plotting backend is a workaround. This can be done e.g....

python,matplotlib,pandas,seaborn

After some research, and not been able to find a "native" Seaborn solution, I came up with the code below, partially based on @Pablo Reyes and @CT Zhu suggestions, and using matplotlib functions: from matplotlib.ticker import * figure(num=None, figsize=(20, 10)) plt.title('Cumulative Distribution Function for ALABAMA population') plt.xlabel('City') plt.ylabel('Percentage') plt.plot(al_df.pop_cum_perc) #set...

Those are errorbars. According to the page you linked to: By default the height of the bars/points shows the mean and 95% confidence interval ...

python,data,matplotlib,annotations,seaborn

annot=True is an argument of heatmap, not pivot_table: sns.heatmap(df3.pivot_table(index='Place', columns='Name', values='00:00:00'), annot=True) ...

python,matplotlib,plot,kernel,seaborn

Here is a solution using scipy and matplotlib only : import numpy as np import matplotlib.pyplot as pl import scipy.stats as st data = np.random.multivariate_normal((0, 0), [[0.8, 0.05], [0.05, 0.7]], 100) x = data[:, 0] y = data[:, 1] xmin, xmax = -3, 3 ymin, ymax = -3, 3 #...

The best thing to do would be to combine the seaborn style and context parameters into one dictionary and then pass it to the plt.rc_context function: import numpy as np import seaborn as sns import matplotlib.pyplot as plt x = np.random.normal(size=100) with plt.rc_context(dict(sns.axes_style("whitegrid"), **sns.plotting_context("notebook", font_scale=1.5))): sns.kdeplot(x, shade=True) ...

You have to tell matplotlib which color to use. To Use, for example, seaborn's default color palette: import matplotlib.pyplot as plt import seaborn as sns import itertools ax=fig.add_subplot(111) palette = itertools.cycle(sns.color_palette()) for f in files: ax.scatter(args, color=next(palette)) The itertools.cycle makes sure we don't run out of colors and start with...

import pandas as pd import numpy as np # just try to replicate your dataframe # ============================================== date = ['2015-07-08', '2015-07-07', '2015-07-07', '2015-07-07', '2015-07-07', '2015-07-07'] location = ['San Diego, CA', 'Bellevue, WA', 'Los Angeles, CA', 'New York, NY', 'Los Angeles, CA', 'Unknown'] text = [1] * 6 df = pd.DataFrame({'Date':...

These are just matplotlib axis ticklabels at integral positions. So you could do df = pd.DataFrame(dict(x=np.repeat(np.arange(21), 10), y=np.random.randn(210))) df.loc[df.x == 20, "x"] = ">= 20" g = sns.factorplot(x="x", y="y", data=df, kind="box") g.axes[0, 0].set_xticks(range(20) + [20.5]) (Note that version version 0.6+ has an ax attribute on single-axes FacetGrid objects that will...

python,matplotlib,pandas,seaborn

I think a combination of the seaborn style and the way matplotlib draws boxplots is hiding your outliers here. If I generate some skewed data import seaborn as sns import pandas as pd import numpy as np x = pd.DataFrame(np.random.lognormal(size=(100, 6)), columns=list("abcdef")) And then use the boxplot method on the...

python,r,data,visualization,seaborn

Thanks Marius I did this from the blog post devtools::install_github("WinVector/WVPlots") library(WVPlots) ScatterHist(diamonds, "price", "carat") and got this ...

You can do it like this: ax = sns.tsplot(sines); # capture axis n = len(ax.xaxis.get_ticklabels()) # count labels ax.set_xticklabels(np.linspace(-15, 15, n)) # set new tick labels Edit: The previous solution is the generic matplotlib's way of manipulating the tick labels. As suggested by seaborn's creator @mwaskom you can also do:...

numpy,matplotlib,scipy,seaborn

Here's what I put together. I tried to emulate your screenshot closely. #------------------------------------------------------------------------------ import matplotlib.pyplot as plt import scipy.stats as stats import numpy as np # Data heights = np.array([50,52,53,54,58,60,62,64,66,67,68,70,72,74,76,55,50,45,65]) weights = np.array([25,50,55,75,80,85,50,65,85,55,45,45,50,75,95,65,50,40,45]) x = heights y = weights # Modeling with Numpy p, cov = np.polyfit(x,y,1,cov=True) # parameters and...

Not perfect (I've haven't had long to play with it), but to give you an idea of the kind of Matplotlib methods you need to use to customize a plot the way you want, there's some code below. Note that to fine-tune a plot like this it is hard to...

seaborn turns the legend frame off by default, if you want to customize how the frame looks, I think you'll need to add frameon=True when you call plt.legend.

python,pandas,matplotlib,bokeh,seaborn

You have to understand that seaborn uses the very matplotlib plotting functions that also pandas uses. As the documentation states, sns.distplot does not accept a weights argument, however it does take a hist_kws argument, which will be sent to the underlying call to plt.hist. Thus, this should do what you...