seaborn

Python: Shifted logarithmic colorbar, white color offset to center

混江龙づ霸主 提交于 2020-06-13 06:30:20
问题 I am struggling to plot my data using pyplot.imshow . I use the 'RdBu_r' colormap, and I need the white color to be at value 1 on a logarithmic scale which is not centered at 1. But how can I do it? I tried 'center=1' which works for seaborn, but there is no such attribute in matplotlib. I also tried this: import matplotlib.pyplot as plt im=plt.imshow(proportion, cmap="RdBu_r", norm=LogNorm(), vmin=0.01, vmax=10) axs=plt.gca() cb = plt.colorbar(im, ax=axs,extend="both") where proportion is my

Custom color palette intervals in seaborn heatmap

帅比萌擦擦* 提交于 2020-06-13 06:09:50
问题 I am trying to plot a heatmap using seaborn library. The plotting function looks like this: def plot_confusion_matrix(data, labels, **kwargs): """Visualize confusion matrix as a heat map.""" col_map = kwargs.get('color_palette', sns.light_palette('navy', n_colors=5, as_cmap=False)) sns.heatmap( vmin=0.0, vmax=1.0, data=data, cmap=col_map, xticklabels=labels, yticklabels=labels, linewidths=0.75, ) The histogram of the data , however, looks like this: Now the issue I am struggling with is that

How to decrease the density of x-ticks in seaborn

瘦欲@ 提交于 2020-06-11 17:12:07
问题 I have some data, based on which I am trying to build a countplot in seaborn. So I do something like this: data = np.hstack((np.random.normal(10, 5, 10000), np.random.normal(30, 8, 10000))).astype(int) plot_ = sns.countplot(data) and get my countplot: The problem is that ticks on the x-axis are too dense (which makes them useless). I tried to decrease the density with plot_.xticks=np.arange(0, 40, 10) but it didn't help. Also is there a way to make the plot in one color? 回答1: Tick frequency

How to decrease the density of x-ticks in seaborn

喜你入骨 提交于 2020-06-11 17:11:51
问题 I have some data, based on which I am trying to build a countplot in seaborn. So I do something like this: data = np.hstack((np.random.normal(10, 5, 10000), np.random.normal(30, 8, 10000))).astype(int) plot_ = sns.countplot(data) and get my countplot: The problem is that ticks on the x-axis are too dense (which makes them useless). I tried to decrease the density with plot_.xticks=np.arange(0, 40, 10) but it didn't help. Also is there a way to make the plot in one color? 回答1: Tick frequency

Quantile-Quantile Plot using Seaborn and SciPy

五迷三道 提交于 2020-06-11 04:06:50
问题 Can anyone give me a way to do a qq plot in Seaborn as a test for normality of data? Or failing that, at least in matplotlib. Thanks in advance 回答1: After reading the wikipedia article, I understand that the Q-Q plot is a plot of the quantiles of two distributions against each other. numpy.percentile allows to obtain the percentile of a distribution. Hence you can call numpy.percentile on each of the distributions and plot the results against each other. import numpy as np import matplotlib

Change the color for ytick labels in seaborn.clustermap

烂漫一生 提交于 2020-06-11 04:03:45
问题 Is it possible to change the colors of the ytick labels in seaborn.clustermap? So for the seaborn Iris example, it is possible to set row colors based on species and plot a clustermap: import seaborn as sns iris = sns.load_dataset("iris") species = iris.pop("species") lut = dict(zip(species.unique(), "rbg")) row_colors = species.map(lut) g = sns.clustermap(iris) And it is possible to get a 1-1 correspondence between the plotted row and row label: g.ax_heatmap.yaxis.get_majorticklabels() Is

How to plot Pandas datetime series in Seaborn distplot?

倾然丶 夕夏残阳落幕 提交于 2020-06-10 18:58:02
问题 I have a pandas dataframe with a datetime column. I would like to plot the distribution of the rows according to that date column, but I'm currenty getting an unhelpful error. I have: df['Date'] = pd.to_datetime(df['Date'], errors='raise') s = sns.distplot(df['Date']) which throws the error: TypeError: ufunc add cannot use operands with types dtype('<M8[ns]') and dtype('<M8[ns]') If I change the column I'm plotting to numeric data then it all works fine. How can I get the datetime column to

How to plot Pandas datetime series in Seaborn distplot?

安稳与你 提交于 2020-06-10 18:57:53
问题 I have a pandas dataframe with a datetime column. I would like to plot the distribution of the rows according to that date column, but I'm currenty getting an unhelpful error. I have: df['Date'] = pd.to_datetime(df['Date'], errors='raise') s = sns.distplot(df['Date']) which throws the error: TypeError: ufunc add cannot use operands with types dtype('<M8[ns]') and dtype('<M8[ns]') If I change the column I'm plotting to numeric data then it all works fine. How can I get the datetime column to

How to plot Pandas datetime series in Seaborn distplot?

喜你入骨 提交于 2020-06-10 18:57:08
问题 I have a pandas dataframe with a datetime column. I would like to plot the distribution of the rows according to that date column, but I'm currenty getting an unhelpful error. I have: df['Date'] = pd.to_datetime(df['Date'], errors='raise') s = sns.distplot(df['Date']) which throws the error: TypeError: ufunc add cannot use operands with types dtype('<M8[ns]') and dtype('<M8[ns]') If I change the column I'm plotting to numeric data then it all works fine. How can I get the datetime column to

Seaborn pairplot off-diagonal KDE with two classes

*爱你&永不变心* 提交于 2020-06-10 09:03:32
问题 I'm trying to look at a Seaborn pairplot for two different classes of variables and I'd like to see KDEs on the offdiagonals instead of scatterplots. The documentation has instructions on how to do a KDE for all of the data, but I want to see separate KDEs for each subclass of data. Suggestions welcome! My code looks something like this: plot = sns.pairplot( df, vars=labels, hue='has_accident', palette='Set1', diag_kind='kde', ) which results in: As you can see the data are sufficiently dense