I am using a seaborn regplot with the following code :
sns.relplot(x="NumCustomers", y="TotalSales", hue = 'StoreLabel', data=stores_month, height = 5, aspect = 2, s = 100);
To generate the following plot :
But the colors are hard to differentiate, after scouring google managed to get this code :
sns.color_palette("tab10")
but nothing happens. How can I change the color pallet to something with better contrast? preferably the tab10 palette.
try
sns.set_palette("Blues")
or
sns.set_palette("Dark")
sns.set_style()
1.white
2.dark
3.whitegrid
4.darkgrid
5.ticks
The set palette api must occur before the relPlot
other apis to try catDist, distPlot, catPlot
I think catPlot would work better
Related
I want to use my own colour palette for the hue. I am following the documentation but for some reason, I can't get it right.
Here is my code:
%matplotlib inline
colors = ["#ff4c8b", "#00d8d5",'#f7f7f7']
sns.set_style(rc={'axes.facecolor':'black','figure.facecolor':'black','axes.grid' : False})
s=sns.lineplot(data=data, x="timestamp", y="close.quote",palette=sns.set_palette(sns.color_palette(colors)), hue='contract_ticker_symbol')
Instead of using the three colours I defined, it uses the default hue palette.Can someone tell me what I am doing wrong
How can I set a matplotlib colormap as my color palette in seaborn?
There is a similar question here, but I was unable to implement it:
import matplotlib.colors as mcolors
cmap = mcolors.LinearSegmentedColormap.from_list('jet')
sns.set_palette(cmap)
The second line throws the following error: from_list() missing 1 required positional argument: 'colors'
The easiest way to hack through seaborn's, ahem, anti-jet security system is to use mpl_palette directly:
sns.mpl_palette("jet", 6)
The more general approach for "given a matplotlib colormap, how do I get a list of discrete colors?" is to call the colormap object with vector of intensities between 0 and 1:
plt.cm.jet(np.linspace(0, 1, 6))
Note that you'll get different results there because seaborn clips the two extreme values, doing something like
plt.cm.jet(np.linspace(0, 1, 8))[1:-1]
Also, while I agree that jet is a basically fine source for a small number of discrete colors, unless you really need colors specifically from jet for some reason, I'd suggest looking into the "turbo" colormap, which is constructed basically the same way but with better perceptual properties.
When I follow the examples in the pandas documentation for visualizing a bar chart:
https://pandas.pydata.org/pandas-docs/version/0.23/generated/pandas.DataFrame.plot.bar.html
See the first example titled Basic plot. with 3 bars.
The pandas documentation shows:
But when I type the same in my local jupyter notebook, I get no color:
Why does my notebook not have color? What can I do to display the colors?
You can pass custom colors to df.plot:
df = pd.DataFrame({"lab":["A","B","C"], "val":[10,20,30]})
df.plot.bar(x="lab", y="val", rot=0, color = ["y","c","m"])
Result:
Here is a LINK to the some more about the one-letter color abbreviations
I’d like to employ the reverse Spectral colormap ,
https://matplotlib.org/examples/color/colormaps_reference.html
for a lineplot.
This works fine with a hex bin plot::
color_map = plt.cm.Spectral_r
image = plt.hexbin(x,y,cmap=color_map)
but when I do
ax1.plot(x,y, cmp=color_map)
this gives me::
AttributeError: Unknown property cmap
Note, I just want to set the colormap and let matplotliob do the rest; i.e. I don't want to have a color=' argument in the .plot command.
You can have a look at this solution - the third variant is what you want:
https://stackoverflow.com/a/57227821/5972778
You need to know how many lines you're plotting in advance, as otherwise it doesn't know how to choose the colours from the range.
I think that seaborn's color_palette function is very convenient for this purpose. It can be used in a with statement to temporarily set the color cycle for a plot or set of plots.
For example:
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
with sns.color_palette("Spectral", n_colors=10):
plt.plot(np.random.rand(5, 10))
You can use with any predefined matplotlib or seaborn colormap, or provide a custom sequence of colors.
I'm using Python to plot a couple of graphs and I'm trying to change the formatting and essentially 'brand' the graph. I've managed to change most things using pylab.rcParams[...], but I can't work out how to change the colour of the markers on the axes and the border around the legend. Any help would be much appreciated. The line below is an example of the type of code I've been using to edit other parts. Basically just lines taken from matplotlibrc, but I can't find them to change everything I want.
pylab.rcParams[axes.labelcolor' = '#031F73'
If you just want to use rcParams, the proper parameters are xticks.color and yticks.color. I can't seem to find a key for the legend frame color. You can set that (along with the tick colors) programmatically though.
import pylab
pylab.plot([1,2,3],[4,5,6], label ='test')
lg = pylab.legend()
lg.get_frame().set_edgecolor('blue')
ax = pylab.axes()
for line in ax.yaxis.get_ticklines():
line.set_color('blue')
for line in ax.xaxis.get_ticklines():
line.set_color('blue')
for label in ax.yaxis.get_ticklabels():
label.set_color('blue')
for label in ax.xaxis.get_ticklabels():
label.set_color('blue')
pylab.show()