New to the site and Geopandas but any advise would be good attached a pic of code and plot. It seems when you use schemes="" it creates a legend which cant be altered. If you remove this you get the normal colorbar legend . If you look at my picture What I am after is a way to make it ncol=10 so the legend goes flat and move it below the plot. Also how do you adjust the font size of title from a legend created with the schemes keyword.
Related
I created a stacked barchart using matplotlib.pyplot but there is no border around the graph so the title of the graph and axes are right up against the edge of the image and get cutoff in some contexts when I use it. I would like to add a small clear or white border around the graph, axes and title. repos_amount is a pandas DataFrame.
Here is my code:
colors = ["Green", "Red","Blue"]
repos_amount[['Agency','MBS','Treasury']].plot.bar(stacked=True, color=colors, figsize=(15,7))
plt.title('Total Outstanding Fed Repos Operations', fontsize=16)
plt.ylabel('$ Billions', fontsize=12)
Here is what the graph looks like:
I tried the suggestions from the link below and I could not figure out how to make it work. I'm not good with matplotlib yet so I would need help figuring out how to apply it to my code.
How to draw a frame on a matplotlib figure
Try adding plt.tight_layout() to the bottom of your code.
Documentation indicates that this tries to fit the titles, labels etc within the subplot figure size, rather than adding items around this figure size.
It can have undesirable results if your labels or headings are too big, in which case you would then need to look into the answers in this thread to adjust the specific box size of your chart elements.
I am creating contour plots with matplotlib/pyplot and trying to print out a customized colorbar as well. I am also attempting to have the colorbar be printed in a completely separate image file from the plot.
sub_fig = plt.figure()
sub_ax = plt.axes()
sub_ax.axis("off")
#cs2 is a contourf object
sep_cb = plt.colorbar(cs2, cax=sub_ax)#, cax = new_figure.legend, ax=new_figure.legend, orientation="vertical")
sep_cb.shrink=0.5
sep_cb.fraction=.1
sep_cb.drawedges=True
# ~sep_cb.solids.set_edgecolor("white")
plt.savefig("colorbar_"+str(ii)+".png")
plt.clf()
So I am referring to the documentation here: https://matplotlib.org/api/_as_gen/matplotlib.pyplot.colorbar.html but I find that changing the settings does not change the appearance of my colorbar. What I want is actually to make it pretty small, and have the sections separated by some whitespace, with the values/ labels to the right. I can't shrink it, or make the values appear. No matter what, it appears like this:
colorbar
However, if I enable that sep_cb.solids line, I get some lines between the sections. But the only reason I even know about this is because of this section:
It is known that some vector graphics viewer (svg and pdf) renders white gaps between segments of the colorbar. This is due to bugs in the viewers not matplotlib. As a workaround the colorbar can be rendered with overlapping segments:
cbar = colorbar()
cbar.solids.set_edgecolor("face")
draw()
It seems that colorbar.solids can be used to set some options on the plot, but I cannot find any documentation on that directly, I don't even see it mentioned elsewhere on the page. Is this some basic pyplot thing I have managed to overlook? Any help would be appreciated, thank you.
I would like to add a legend which explains what each span represents in the figure and I'm having trouble to find out how to do that, since I'm new to Python/matplotlib.
So, I don't want a legend which explains each of the lines in my graphic, but I want to split the graphic using spans in different color and explain what each color (span) means.
How to do that?
I'm using this to add the spans, just to avoid confusion:
ax.axvspan(10, 300, alpha=0.2, color='red')
I'm adding an example to make things more clear. Instead of Men and Women there should be some other text and appropriate colors.
Since the legend you want does not seem refer to the actual data but some properties in your plot, I'd recommend to use pylot.text or pyplot.annotate. With these commands you can freely position your "legend".
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