I'm using sns.FacetGrid to plot 10 subplots. I'd like to flex the y-axis to be different for each subplot.
At the moment it automatically uses the same for all subplots. Would it be possible to customize it to make it more specific for each subplot?
See the documentation for facet grid here
share{x,y}bool, ‘col’, or ‘row’ optional If True, the facets will
share y axes across columns and/or x axes across rows.
Be advised that this also breaks alignment across columns and will most likely not produce the results you intended. One Y axis will be displayed, which will be only valid for the leftmost plot.
Related
I am aiming to combine two types of charts - a horizontal bar chart using a categorical axis and some form of line, scatter, violin, or similar chart that displays a trace paired with each category on the same axes but "dithers" up and down around some bounds.
Below is sort of what I'm trying to create. However, the shape of the violin chart is generated automatically behind the scenes from scattered points. In my use case, I already have what the distributions are and I'm trying to plot them over top of related data.
I can't find a utility in Plotly that allows me to specify a categorical axis, but then offset points, lines, etc from that category-derived position on the axis.
I have a reasonably complicated grid of subplots that involves two sets (one on the left and another on the right) of columns plotting a set of quantities for each row, separated by a common legend to label the entries in each row.
Here is a sample of what I want to accomplish
Using matplotlib with constrained_layout = True works 95% perfectly for applying the out optimal sizes & spacing for the columns, down to the tricky case of having the legend run down the middle. The remaining 5% is highlighted in red, where the wordy x-axis tick labels seem to push away the columns: it would be perfect if there was a way to make the layout engine "ignore" the tick labels in determining the spacing.
Methods using other libraries are also appreciated. Thank you in advance.
What I tried:
subplots_adjust
GridSpec
The main difficulty with those attempts:
constrained_layout is incompatible with those settings, so one must sacrifice the optimized legend spacing at the cost of getting the column spacing right, or vice versa.
In python seaborn, What is the difference between countplot and catplot?
Eg:
sns.catplot(x='class', y='survived', hue='sex', kind='bar', data=titanic);
sns.countplot(y='deck', hue='class', data=titanic);
seaborn.countplot
Shows the counts of observations in each categorical bin using bars.
seaborn.catplot
Provides access to several axes-level functions that show the relationship between a numerical and one or more categorical variables using one of several visual representations.
There is a lot of overhead in catplot, or for that matter in FacetGrid, that will ensure that the categories are synchronized along the grid. Consider e.g. that you have a variable you plot along the columns of the grid for which not every age group occurs. You would still need to show that non-occuring age group and hold on to its color. Hence, two countplots next to each other do not necessarily make up one catplot.
However, if you are only interested in a single countplot, a catplot is clearly overkill. On the other hand, even a single countplot is overkill compared to a barplot of the counts.
my problem is that I could only find answers for plots sharing the same y-axis units.
My graphs are defined as follows:
#Plot1
sns.set_style("white")
sns.catplot(y="Reaction_cd_positive", x="Flux_cd_positive",
kind="bar",height=4, data=CDP,aspect=1.5)
#Plot2
sns.catplot(y="Reaction_cd_negative",x="Flux_cd_negative",
kind="bar",height=4, data=CDN, aspect=1.5)
Thank you in advance!
Ok, let me translate this. You are using seaborn in a jupyter notebook. You want 2 barplots next to each other within the same figure, instead of two individual figures. Since catplot produces a figure by itself, there are two options.
Create a single catplot with two subplots. To this end you would need to concatenate your two DataFrames into a single one, then use the col argument to split the data into the two subplots.
Create a subplot grid with matplotlib first, then plot a barplot into each of the subplots. This is shown in this question.
I have two subplots I'd like to show horizontally. The x and y axis labels are exactly the same for both plots, even though the ticks are different. What is the most concise way I can plot them horizontally?
Plot 1:
Plot 2:
You can check Sharing axis limits and views.
Other specific examples are found here and here.
In the first link you will find an example of plots side by side. The other two examples the subplots are in a column but it is trivial to set them horizontally