Stacked Bar Chart with Centered Labels

The following method is more succinct, and easily scales. Putting the data into a pandas.DataFrame is the easiest way to plot a stacked bar plot. Using pandas.DataFrame.plot.bar(stacked=True), or pandas.DataFrame.plot(kind=’bar’, stacked=True), is the easiest way to plot a stacked bar plot. This method returns a matplotlib.axes.Axes or a numpy.ndarray of them. Since seaborn is just a … Read more

FacetGrid change titles

Although you can iterate through the axes and set the titles individually using matplotlib commands, it is cleaner to use seaborn’s built-in tools to control the title. For example: # Add a column of appropriate labels df_reduced[‘measure’] = df_reduced[‘ActualExternal’].replace({0: ‘Internal’, 1: ‘External’} g = sns.FacetGrid(df_reduced, col=”measure”, margin_titles=True) g.map(plt.hist, “ActualDepth”, color=”steelblue”, bins=bins, width=4.5) # Adjust title … Read more

How do I increase the line thickness for sns.lineplot?

As you can see from seaborn.lineplot documentation, the function accepts matplotlib.axes.Axes.plot() arguments, which means you can pass the same arguments you can to matplotlib function in this documentation. If you want to simply adjust the width of your lineplots I find this the easiest: pass an argument linewidth = your_desired_line_width_in_float , for example, linewidth = … Read more

How to change the marker size in lmplot

You want to use scatter_kws={“s”: 100} As in: lm = sns.lmplot(x = “totalX”, y = “NormI”, hue = “Data Type”, data = df, palette=”Set1″, legend_out=False, scatter_kws={“s”: 100}) You can amend the integer value (currently 100) to change the size of the markers. I don’t know what your hue or palette data are, but this should … Read more

Plot a histogram such that the total height equals 1

When plotting a normalized histogram, the area under the curve should sum to 1, not the height. In [44]: import matplotlib.pyplot as plt k=(3,3,3,3) x, bins, p=plt.hist(k, density=True) # used to be normed=True in older versions from numpy import * plt.xticks( arange(10) ) # 10 ticks on x axis plt.show() In [45]: print bins [ … Read more

Custom Annotation Seaborn Heatmap

This feature has just been added in the recent version of Seaborn 0.7.1. From Seaborn update history: The annot parameter of heatmap() now accepts a rectangular dataset in addition to a boolean value. If a dataset is passed, its values will be used for the annotations, while the main dataset will be used for the … Read more

Barplot savefig() returning an AttributeError

I solved the issue by changing ax.savefig(‘file.png’) to ax.figure.savefig(‘file.png’) I guess accessing the figure directly is one way to get to the savefig() method for the barplot. @WoodChopper also has a working solution, but it requires another import statement, and utilizing pyplot’s savefig() directly. Either solution does require setting matplotlib.use(‘Agg’) to get around the DISPLAY … Read more

Discrete legend in seaborn heatmap plot

Well, there’s definitely more than one way to accomplish this. In this case, with only three colors needed, I would pick the colors myself by creating a LinearSegmentedColormap instead of generating them with cubehelix_palette. If there were enough colors to warrant using cubehelix_palette, I would define the segments on colormap using the boundaries option of … Read more

Customize the axis label in seaborn jointplot

sns.jointplot returns a JointGrid object, which gives you access to the matplotlib axes and you can then manipulate from there. import seaborn as sns import numpy as np # example data X = np.random.randn(1000,) Y = 0.2 * np.random.randn(1000) + 0.5 h = sns.jointplot(X, Y) # JointGrid has a convenience function h.set_axis_labels(‘x’, ‘y’, fontsize=16) # … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)