How to use hist_kws in seaborn displot - python-3.x

I want to plot histogram and kde line in the same plot with different color. I want to set green color for the histogram and blue color for the kde line. I managed to figure out using line_kws to change the kde line color but hist_kws is not working on the displot. I have tried using histplot but I am unable to put different color for the hist and the line.

You can use line_kws={'color': ...} to change the color of the kde line. And directly facecolor=... to change the color of the histogram.
The following code has been tested with seaborn 0.11.1 and displot with the default kind (kind='hist') and no hue:
sns.displot(..., facecolor=...) changes the color of the histogram faces
sns.displot(..., edgecolor=...) changes the color of the histogram edges
sns.displot(..., color=...) changes the color of the kde line (when kde=True)
sns.displot(..., line_kws={'lw':...}) changes the parameters of the kdeline, except the color
Here is an example:
import seaborn as sns
penguins = sns.load_dataset('penguins')
sns.displot(data=penguins, x="flipper_length_mm", kde=True, col="species", color='red',
line_kws={'lw': 3}, facecolor='lime', edgecolor='black')
Seaborn's forte is the hue parameter, placing multiple distributions together, for which it is very handy that corresponding kde and histogram get the same color. When using hue, the above coloring gets overridden.

hist_kws is an optional argument in distplot which takes only values in a dictionary. You can use this to set linewidth, edgecolor etc.
Example for your ref

Related

User-friendly names for plotly CSS colors?

I know that one can view the plotly default color sequence as:
import plotly.express as px
print(px.colors.qualitative.Plotly)
which yields a list of CSS colors:
['#636EFA', '#EF553B', '#00CC96', '#AB63FA', '#FFA15A', '#19D3F3', '#FF6692', '#B6E880', '#FF97FF', '#FECB52']
I can specify a color in plotly by selecting an element from this list. For example:
go.Scatter(x=x, y=y, line={"color": '#636EFA'})
Are there more user-friendly names defined within plotly for these colors, or is CSS color the only way to refer to the them?
I feel you :)
Actually yes!
1. For "continuous color scales": (2. For discrete color scales)
2. For discrete color scales:
(Have fun ;))

How to draw a coordinate map containing both horizontal and vertical boxplot with matplotlib

I want to draw a picture like this using matplotlib.
How to do that?
Thank you in advance.
Example/i.stack.imgur.com/Vk57A.png
seaborn.jointplot might be what you're looking for. Specify to draw boxplots in the marginal plot and a regplot in the "main plot".
Seaborn builds on top of matplotlib, so you can still modify linecolors, markercolors etc. and draw annotations with plt.annotate.

Changing Yellowbrick visiualization colors

In Yellowbrick visiualization library, the default color for the classification report is red: from lighter to darker tones. Is there a way to change this color and use green, blue, etc.?
when defining the visualizer, you can set a color sequence(cmap).
viz = ClassificationReport(model, cmap='PuRd')
viz.score(X_test, y_test)
You can find the different color sequences at
http://www.scikit-yb.org/en/latest/api/palettes.html#color-sequences

gmtset BASEMAP_FRAME_RGB transparency

I want to not have my basemap axes visible for an image I'm making in GMT with several plots in it. So far I have made them white using:
gmtset BASEMAP_FRAME_RGB = white
However some of the plots partially overlap and the white axes can be seen over the plots - any ideas on how to fix this? By making the basemap frame transparent ideally.
In fact I've realised I can change the order I do the plots in so that the overlap doesn't matter - also replaced -B... with -G255 to plot on a blank square.

matplotlib's axvspan converts marker colors in scatter plot but not in ordinary plot

I recently noticed the following phenomen in matplotlib (using v1.3.1 with Python3.3):
Minimal code example
import matplotlib.pyplot as plt
plt.plot(range(5),5*[3],'o', color="r", label="plt.plot")
plt.scatter(range(5),5*[2], color="r", label='plt.scatter')
plt.axvspan(1.5,4.5, color='yellow', alpha=0.5)
ax=plt.gca()
ax.legend(loc=6)
plt.savefig('adjusted_colors.png')
yields a plot with partially adjusted marker colors -- sorry for being not able to show the plot here -- namely markers plotted using pyplot's scatter-function in the area spanned by axvspan.
In contrast, color of markers plotted via pyplot's plot-function is not converted.
Any ideas about how to avoid marker color's adjustment in case plt.scatter is used for plotting, respectively, how to turn it on in case of using plt.plot?
The reason the "colors are adjusted" is not because the color actually changes, but because the scatter result (which is a PathCollection object) is being viewed through a half-transparent colored rectangle that it is underneath. The same doesn't happen to the result of plot (which is a Line2D object) because it lies above the rectangle.
Matplotlib uses an attribute called zorder when it displays artists in a figure (most everything that lives in a matplotlib plot is an artist). The defaults set the plot's zorder to 2, whereas the rectangle and the scatter both have a zorder of 1, and the rectangle defaults to existing "higher" (not sure exactly why, but it is what it is). You can force the scatter points to lie above the rectangle by specifying the zorder keyword:
plt.scatter(range(5),5*[2], color="r", label='plt.scatter', zorder=2)
Or, if you want the opposite, do the same to move the plot points below the rectangle:
plt.plot(range(5),5*[3],'o', color="r", label="plt.plot", zorder=0)

Resources