This question already has answers here:
Move seaborn plot legend to a different position
(8 answers)
Closed 1 year ago.
Whenever I try to use the hue feature in seaborn it works fine if the column used in Hue has lesser values. But in case of larger number of values it covers/shadows the main plot. Is there anyway to keep/position the hue column value details not on the top of the main plot.
I believe easiest solution is just to enlarge fig size, as plot will take smaller relative size.
Seaborn's doesn't handle well with legends in my opinion. You can edit legend using matplotlib function: matplotlib's legend guide
Some possible solutions:
Move legend outside: Move legend outside figure in seaborn tsplot
resizing the plot: How to move the legend in Seaborn FacetGrid outside of the plot?
smaller text in legend(see first answer): How to put the legend out of the plot
Related
When plotting a line with many points, matplotlib automatically hides some x-axis ticks/labels to make sure all labels can fit.
If I want to plot a bar chat with many points, is there anyway to make matplotlib think of the x-axis in the same as with a line plot? Right now it's trying to squeeze in all the labels.
I would suggest specifiying the list of xtick labels :
plt.xticks([80,150,300]) ### In this case these are numbers, change them to your values
This question already has an answer here:
Show categorical x-axis values when making line plot from pandas Series in matplotlib
(1 answer)
Closed 4 years ago.
I have imported an Excel file and want to plot a 2D graph by using data from that file.
I have used matplotlib to plot graph by using
df.plot("Col1","Col2") but its is not showing X-labels in the graph which should be text(Col1)
What changes should I apply to Code()?
According to pandas docs your code is correct. Perhaps you can try another method of showing the x-label in order to see where the problem comes from. You can try the following
ax = df.plot() # retrieve the matplotlib Axes object
ax.xlabel("Col1") # set the x-label
ax.ylabel("Col2") # set the y-label
See this docpage
https://matplotlib.org/api/_as_gen/matplotlib.pyplot.xlabel.html
How to matplotlib draw figure with different spacing?
specifically, how to draw this one?
The plot shown in the question is plotted on a 'logit' scale.
ax.set_xscale('logit')
ax.set_yscale('logit')
You may refer to the scales example.
I'm creating a plot with factorplot and then trying to add a subplot on top of each box. How can I get the x-axis locations of each individual box in the factor plot to put another line on top?
Maybe there's a way to get all the x-axis values of each box plot on the axes?
Here's my basic factor plot:
I want to add 1 subplot (the circle) in the middle of each box plot. However, I cannot figure out how to get the x-value of each box to properly space the points.
I see a lot of code for positions and offsets in the seaborn source that lays these out. However, I'm wondering if there is a more straight-forward method to get this information or at least approximate it.
As per #mwaskom's comments, you can use sns.stripplot() (and now also sns.swarmplot()) to include your data points with a data summary plot such as a box or violinplot.
I have the following graph, consisting of several lines:
Now, I would like to label all the lines in the plot. However, using legend() crams all the labels together in a box, which makes the plot somewhat difficult to interpret. What I'd like to to instead is to use inline labels. My ideal output would use labels like the following matplotlib contour plot, but with text labels for lines instead of numbers:
I haven't been able to find out how to do this in the matplotlib documentation. Is there a way to achieve this? If not, what other software could I use to generate this type of plot?
May I suggest another solution to your problem. Since in your case legend overlaps the charts you might just want to move the legend outside of the plot.
Method do move legend outside of plot is described here:
Moving matplotlib legend outside of the axis makes it cutoff by the figure box