How to adjust cbar label position in sns.clustermap? - seaborn

I'm ploting a seaborn clustermap and have problems to position the colorbar label. This is my code:
heatmap_plot = sns.clustermap(table, method=method, metric=metric,
row_colors=row_colors,
col_cluster=col_cluster, row_cluster=row_cluster,
cmap=color_scheme,
xticklabels=True, yticklabels=True,
# linewidths=1,
cbar_kws={'label': cbar_label})
plt.setp(heatmap_plot.cax.yaxis.get_label(), rotation=270)
When I want to rotate cbar label text, it's overlapping with ticks and I have no idea how reposition it. Does anyone have an idea how to solve the problem?

You could leave out the colorbar label from the main sns.clustermap call and then do
heatmap_plot.cax.set_title("my cbar label")

Related

Seaborn: Place the y-label in a line with the points on the coordinate axis

I want to place the y-label in the left upper corner in line with the points on the coordinate axis. The label should replace the axes ticks in that area.
Here is an example from a paper that I read:
I found a lot of information on how to move the label to the top left corner. However, how do I remove the ticks and move the label closer to the axes?
The best solution that I found:
# style
plt.figure(figsize=(8,8))
sns.set_style("white")
sns.set_context("paper", font_scale=1.6)
# plot
sn_dis1 = sns.displot(idx_pix_count_pd, hue='Dataset', x="Size", fill=True, palette='bwr', kind="hist", bins=500)
# y-achses
axes = sn_dis1.axes.flatten()
axes[0].set_ylabel("Count", fontsize=16)
axes[0].yaxis.set_label_coords(.0, .9)
The approach proposed by Trenton (Edit: Who delete his comment to my original question) did not work for me as the text is horizontal vertically. But I learned something from it and am sure that you somehow can make it work like that.
# style
plt.figure(figsize=(8,8))
sns.set_style("white")
sns.set_context("paper", font_scale=1.6)
# plot
sn_dis1 = sns.displot(idx_pix_count_pd, hue='Dataset', x="Size", fill=True, palette='bwr', kind="hist", bins=500)
# y-achses
ticks = range(8)
labels= list(range(7)) + ['Density']
axes = sn_dis1.axes.flatten()
axes[0].set_yticklabels(labels)
# do not show default label
axes[0].get_yaxis().get_label().set_visible(False)

tick axis getting out of svg barchart

I am trying to do a barchart with Recharts but ticks on both axis are getting out of svg:
Do you know to solve this ?
In your example, your tick labels have an angle that puts them out of the svg zone. To turn back your tick labels like on a line, you need to either update the angle prop to 0, like the following:
<XAxis dataKey="name" angle={0} />
Removing the angle prop from the XAxis would work as well, since its default value is 0.

CanvasJS unable to change x axis format on stacked area chart

I have a CanvasJS stacked area chart which is ignoring my attempts to change the x axis labels font size and color. I use this code:
axisX: {
gridThickness: 0,
interval: 5,
lineThickness: 1,
labelFontColor: "#000000",
labelFontSize:12
but my axis labels remain unchanged from the default size and color:
is there anything special required for stacked area charts?
Thanks in advance.
Issue was that the axis format property was not inside the x axis jason node, so user error! Thanks for the reply Indranil.

Adding a legend to a scatter plot with two sets of data

I plotted my data in the following way:
G=[(1.42*1e-5, 8.5*1e-2), (1.19*1e-5, 7.8*1e-2), (1.03*1e-5, 6*1e-2), (8.95*1e-6, 4.7*1e-2), (7.63*1e-6, 3.8*1e-2), (7.12*1e-6, 3.2*1e-2), (5.72*1e-6, 2.6*1e-2)]
PN=[5*1e3, 10*1e3, 20*1e3, 40*1e3, 80*1e3, 120*1e3, 200*1e3]
figure(5,figsize=(12,10))
for PNe, Ge, in zip(PN, G):
scatter([PNe]*len(Ge), Ge, color=['red', 'green'])
grid()
xlim(xmin=0, xmax=200000)
#ylim(ymin=0, ymax=1)
xlabel('Number of particles')
ylabel(r'Energy release rate')
legend(['$G_{simulation}$','$G_{analytical}$'])
and what I get as legend is the following: legend
As you see the colors are not attributed properly.
I need to assign red to G_{analytical} and green to G_{simulation}.
What am I doing wrong here?
Thanks
So here is the deal,
Simply changing the plot format to
Gs=[8.5*1e-2, 7.8*1e-2, 6*1e-2, 4.7*1e-2, 3.8*1e-2, 3.2*1e-2, 2.6*1e-2]
Ga=[1.42*1e-5, 1.19*1e-5, 1.03*1e-5, 8.95*1e-6, 7.63*1e-6, 7.12*1e-6, 5.72*1e-6]
PN=[5*1e3, 10*1e3, 20*1e3, 40*1e3, 80*1e3, 120*1e3, 200*1e3]
figure(5,figsize=(12,10))
scatter(PN, Gs, color='red', label='$G_{Simulation}$')
scatter(PN, Ga, color='green', label='$G_{Analytical}$')
grid()
xlim(xmin=0, xmax=200000)
#ylim(ymin=0, ymax=1)
xlabel('Number of particles')
ylabel(r'Energy release rate')
legend()
does the job.
Here is the result: Label with correct color assignment
There we go.

Can't make image_url work in Bokeh (Python)

I tried to reproduce the solution from: How do I work with images in Bokeh (Python) , but it doesn't work. For that, I find an image on the net and put it in place of the 'url' field but the plot is just blank! From the original solution bokeh ask me to add up w and h params which I suppose are the width and height of the pic. Also I dropped x_range and y_range within figure() to wipe out the horizontal and vertical lines of the plot.
from bokeh.plotting import figure, show, output_notebook
output_notebook()
p = figure()
p.image_url( url=[ "http://pngimg.com/uploads/palm_tree/palm_tree_PNG2504.png"],
x=1, y=1, w=253, h=409)
show( p)
Anyone could tell me what's going on ?
Bokeh can't auto-range ImageURL it seems. So if there are no other glyphs, you need to provide explicit ranges. Additionlly, the default anchor is upper_left IIRC so it may be that our image is rendering off-canvas and you don't realize it. The code below works with Bokeh 0.12.5:
from bokeh.plotting import figure, show, output_file
output_file("foo.html")
p = figure(x_range=(0,500), y_range=(0,500))
p.image_url( url=[ "http://pngimg.com/uploads/palm_tree/palm_tree_PNG2504.png"],
x=1, y=1, w=253, h=409, anchor="bottom_left")
show(p)
Without the anchor set, the image plots blow the plot region (have to pan to see it)

Resources