Crop Whitespace above and below a Matplotlib SubPlot - matplotlib

I'm doing a matplotlib subplot and it results with a lot of whitespace above and below it, while on the sides it is fine.
Is there a way to crop this whitespace imposing some length or pixes values?
I'm using this code right now, I treid also without the tight but then it will result also with some white space on the sides. While if I remove the dpi nothing change, the whitespace is still present.
plt.savefig(figDir + "\VM", bbox_inches='tight', dpi=1000)

Related

Dots repel in Pandas scatterplot

I am trying to draw a scatterplot where visualizing all the dots hue and size is important.
However, some dots are localized at the same location x,y therefore they overlap, and we cannot see them well.
I know there is the equivalent of the 'repel' function in Pandas for the dots labels with the following script.
https://github.com/Phlya/adjustText
Would anyone know if there is another software that allow to repel the dots themselves, and not just the text annotation?

Inserting Upward Triangle In Mathtext String Matplotlib

I am using the function plt.text in Matplotlib to produce text within my plot. In addition, I am using Mathtext to bold a portion of the text string, as seen in this piece of code:
plt.text(0.01,0.32,fill(r"$\bf{Peaks:}$"+appended_text,57), ha='left',va="top", multialignment="left", fontsize=10.5, wrap=True)
Within my plot, I am currently denoting specific points with an filled upward triangle ("^" via plt.plot in Matplotlib), and would like to use this filled upward triangle symbol within the Mathtext bolded string above.
My initial approach was to try: r"$\bf{Peaks\ [^]:}$", however this simply moved the closed portion of the bracket as an exponential symbol.
Is there a way to replicate this filled triangle within Mathtext?
How would I use

matplotlib xticks misplaced after using ax.set_xlim()

When I set xlim with ax.set_xlim() my xtick labels are all shifted by one space to the left.
fig,axes=plt.subplots(2,1,sharey=True)
x=list(range(0,9))
y=list(range(1,10))
df=pd.DataFrame({'x':x,'y':y})
ax1=df.plot('x','y',ax=axes[0])
xticklabels=x
ax1.set_xticklabels(x)
after I add this line to the code
ax1.set_xlim(-0.2,8.2)
xticks are wrongly placed:
While you set the ticklabels to be the elements of a list, you do not specify the actual tick positions. So you leave it to the automatic AutoLocator to place the tick positions, but then set some custom labels to those ticks.
This will in general not give reasonable results.
As a rule of thumb: If you fix the labels, you need to fix the positions as well.
ax.set_xticks(x)
ax.set_xticklabels(x)

How to control the specific size of plot in matplotlib?

Let us suppose that I am plotting a few plots with pyplot/matplotlib. Now, the first has to have tick marks and tick labels, and only the first. The last has to have a colorbar and some marks for scale. If I do a script specifying the figure size, the plot proper in the last and first plots is drawn with smaller sizes, as the figure has to make room for the extra markings. And I seem to be not able to control that, in an automatic way, like making the other plots at the same scale inside a larger figure or something like that.
Example code (it looks a little non-pythonic because I am using PyPlot inside Julia):
using PyPlot
SomeData=randn(64,64,3)
for t=1:3
figure(figsize=(3.0,3.0))
imagen=imshow(SomeData[:,:,t], origin="lower")
if t!=3
xticks([])
yticks([])
else
tick_params(labelsize=8, direction="out")
end
if t==1
cbx=colorbar(imagen, fraction=0.045, ticks=[])
cbx[:set_label]("Some proper English Label", fontsize=8)
end
savefig("CSD-$t.svg",dpi=92)
end
Thanks in advance-

Positioning figure and table in figure

I'm trying to put both a plot and a table in a figure, but I want some whitespace to separate the two. How do I position the table/plot at arbitrary positions? What I have now is the table of values showing up IMMEDIATELY under the x-axis (so that it's actually colliding into my axis labels...)
I don't know matplotlib at all...The documentation is not written very well either...
To position something in a figure you have to use the function set_position([left, bottom, width, height]). Example:
matplotlib.pyplot.axes().set_position([0.15, 0.20, 0.80, 0.70])