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)
- Performance Issue: Seaborn Lineplot Execution Time Discrepancy with and without Timezones HOT 5
- sns.barplot(index ="index", x=" data_column1", y="data_column2") creates error due to whitespace before column name in x, y parameters HOT 1
- AttributeError: module 'numpy' has no attribute 'float'. HOT 6
- Add Color Universal Design palette HOT 2
- Palette does not support the use of defaultdict with missing values HOT 4
- `so.Hist` ignores `common_norm=True` for the `"density"` aggregate statistic
- Differences when displaying standard deviation on line and barplot HOT 1
- catplot with numeric hue and hue_order: empty legend handles HOT 2
- sns.lineplot `hue`param will make wrong number of classes when it pass a field whose dtype is not `category` HOT 1
- Calling scatterplot with size and hue raises TypeError HOT 3
- HI ,we need seaborn cpp HOT 2
- histogram with fixed binwidth - unexpected results for last column HOT 4
- Docu: Reference to root package missing in object.inv file HOT 6
- Value error in histplot with binwidth smaller than half the data range HOT 2
- UnboundLocalError: local variable 'boxprops' referenced before assignment HOT 11
- Doubts about using two types of graphics to draw simultaneously HOT 2
- Palette setting ignored unless passed directly for numeric hues HOT 1
- scatter plot with wide data: markers=False gives an error HOT 3
- countplot taking long time for Series and not Pandas 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.