Comments (5)
Hi, this isn't a reproducible example so it's really impossible to say. The colorbar on a heatmap will "steal" space from the axes with the heatmap by default, maybe that's what you're seeing.
I'm going to close but can reopen with a reproducible example that demonstrates an issue in seaborn.
from seaborn.
Hi,
i am aware that the color bar steals space, but in the image i uploaded i removed the axes (the pareto bar also contains second axis) its also taking space, with the axes its even more significant.
this is how it looks like with axes:
here is the data i used for the plotting
test_data.zip
and the code i used for it:
`
def plot_heatmap_to_ax(data,ax,title=None,annot=False,mark_max=True,x_items=10,y_items=10):
import seaborn as sns
assert len(data.columns) == 3,print('only 3 columns dataframe: columns,rows,values')
(x1,x2,y)=data.columns
plot_df = data.pivot(index=x1, columns=x2, values=y)
plot_df = plot_df.loc[plot_df.sum(axis=1).sort_values(ascending=False).index[:y_items], plot_df.sum(axis=0).sort_values(ascending=False).index[:x_items]]
cmap = 'OrRd' # 'RdYlGn_r'.
p = sns.heatmap(data=plot_df, ax=ax, xticklabels=1, cmap=cmap, robust=True, annot=annot, yticklabels=True)
ax.title.set_text(title)
if mark_max:
from matplotlib.patches import Rectangle
text_color = 'midnightblue' # 'navy'
mark_text = 'Max '
ax.text(0, len(plot_df), f'{mark_text} {x2}', color=text_color, weight='bold', rotation=90,size=10, ha='left') # , fontweight='bold'
ax.text(0, 0, f'{mark_text} {x1}', color=text_color, weight='bold', rotation=0, size=10,va='top') # 'baseline', 'center_baseline'
ax.add_patch(Rectangle((0, 0), 1, plot_df.shape[0], linestyle='--', fill=False, edgecolor='red'))
ax.add_patch(Rectangle((0, 0), plot_df.shape[1], 1, linestyle='--', fill=False, edgecolor='red'))
return ax
def plot_pareto_to_ax(data,ax,x,y1,y2,axis_labels,annot=False,title=None):
if not isinstance(y1, list):
y1 = [y1]
labels = y1.copy()
if y2 is not None:
if not isinstance(y2, list):
y2 = [y2]
labels += y2
data[x] = data[x].astype(str)
p1 = ax.plot(data[x], data[y1], label=y1)#, color=colors[l], marker='o')
if annot:
for j in y1:
for k in range(len(data)):
ax.annotate(data[j][k], (data[x][k], data[j][k]))#, fontweight='light')
ax.set_xlabel(axis_labels[0])
ax.set_ylabel(axis_labels[1])
ax.grid(axis='y')
if y2 is not None:
ax2 = ax.twinx()
# set color cycle to next color
for advance in range(len(y1)):
ax2._get_lines.get_next_color()
p2 = ax2.plot(data[x], data[y2], label=y2,linestyle='None')
if annot:
for j in y2:
for k in range(len(data)):
ax2.annotate(data[j][k], (data[x][k], data[j][k]))#, fontweight='light')
ax2.set_ylabel(axis_labels[2])
# set joined legend
lns = p1+p2
ax.legend(lns, labels, loc=1)
ax.set_xticklabels(data[x], rotation=90)
ax.title.set_text(title)
return ax
fig, axes = plt.subplots(ncols=1, nrows=2 , figsize=(7,7))
axes[0] = plot_heatmap_to_ax(data,ax=axes[0],title='Test', annot=False, mark_max=False, x_items=30, y_items=30)
axes[1] = plot_pareto_to_ax(data=Fleet_summary,ax=axes[1], x='x', y1=['y1', 'y1-2'], y2='y2',axis_labels=['x', '% y', '# y2'], title='')
`
from seaborn.
To demonstrate that this is a problem in seaborn, you'll need to clean up your example and make it much simpler, and show that it doesn't happen if you use matplotlib directly.
from seaborn.
i think this example is very simple to show the matplotlib has no right padding as the seaborn, you can easily add more matplotlib plots by duplicating axes[1] multiple times, create the exact same plot (or is you prefer create different type of plot), and change the number of rows accordingly, you will see that all matplotlib plots will have same width except the seaborn plot.
n=5 fig, axes = plt.subplots(ncols=1, nrows=n , figsize=(7,7)) axes[0] = plot_heatmap_to_ax(data,ax=axes[0],title='Test', annot=False, mark_max=False, x_items=30, y_items=30) for i in range(1,5): axes[i] = plot_pareto_to_ax(data=Fleet_summary,ax=axes[i], x='x', y1=['y1', 'y1-2'], y2='y2',axis_labels=['x', '% y', '# y2'], title='')
you can adjust the position, seaborn to be first/last/in the middle and see where this comes from, etc...
BR,
Nir
from seaborn.
Hi, i resolved it, it was the layout setting in the figure creation, adding layout="constrained" to figure forces all axes to same width, you can close it.
Thanks,
Nir
from seaborn.
Related Issues (20)
- Kwargs can't be passed from seaborn to matplotlib HOT 1
- Incorrect plotting of exactly overlapping scatter with `hue` and `hue_order` HOT 3
- Adding plot type metadata to support textual figure descriptions HOT 2
- TypeError: Cannot interpret 'Float64Dtype()' as a data type with pandas extension types HOT 2
- Consider adding mpl.Figure as an optional argument to subplot functions / classes. HOT 1
- AttributeError: module 'numpy' has no attribute 'typeDict'
- categorical plots - unused categories mess up element spacing and width HOT 4
- Customizing context or style as in seaborn as in matplotlib? HOT 1
- Introducing `seaborn_objects_recipes` Library HOT 2
- secondary y axis is messing up the y-axis labels HOT 1
- Adding precomputed errorbars to pointplot HOT 1
- Seaborn with scanpy and statannotations HOT 1
- Linear regression constrained to pass through origin HOT 2
- Dual axis plot broken in 0.13.2 (vs. 0.12.2) HOT 2
- Controlling color of both line and bar at same time using object interface HOT 4
- How to hide legend while using seaborn.objects? HOT 1
- Cannot plot certain data with kdeplot, warning that dataset has 0 variance which is not. HOT 1
- Older Versions of Seaborn Incompatible with Matplotlib 3.9.x HOT 3
- TypeError with seaborn.kdeplot when using fill=True and categorical hue HOT 3
- ModuleNotFoundError: No module named 'seaborn' HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from seaborn.