remove white spaces in images subplot in python and save it [duplicate] - matplotlib

This question already has answers here:
Reduce the gap between rows when using matplotlib subplot?
(3 answers)
Closed 5 years ago.
I want to create a subplot of spectrograms in python3, using the following code.
My problem is that I have white spaces between plots and
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
j=0
plt.clf()
f, axarr= plt.subplots(4,5, gridspec_kw = {'wspace':0, 'hspace':0})
f.tight_layout()
for i, ax in enumerate(f.axes):
j=j+1
im = ax.imshow(syllable_1.transpose(), vmin=0, vmax=syllable_1.max(),
cmap='pink_r')
plt.xticks([], [])
#ax[j].autoscale_view('tight')
#ax.set_xticklabels([])
#ax.set_yticklabels([])
#plt.subplots_adjust(left=0.1, right=0.85, top=0.85, bottom=0.1)
plt.subplots_adjust(wspace=0, hspace=0)
plt.savefig("myfig9.png", bbox_inches='tight')
the result is as follows:
could you please suggest me some solutions to solve it.
Thanks in advance

Just to lest you know, I add aspect='auto' to my plot code and it is solved. I used the following link. It seems that I did not use good keywords for search. Thanks

Related

How to remove the whitespaces between points in scatterplot [duplicate]

This question already has answers here:
How to change spot edge colors in seaborn scatter plots
(3 answers)
Closed 1 year ago.
I have used the scatterplot command to make a plot of nurse schedules, however whenever the points are close, there is this annoying whitespace, which I would like to get rid of. An example:
So whenever the points are close there appear this white gap...
To plot the red dots I have used this command:
sns.scatterplot(x='xaxis', y='nurses', data=df_plot, marker=',', color='r', s=400,ci=100)
It looks like your markers are being drawn with white edges. You can remove these using edgecolor='None' as an option to sns.scatterplot.
sns.scatterplot(x='xaxis', y='nurses', data=df_plot,
marker=',', color='r', s=400, ci=100, edgecolor='None')
A small example to demonstrate this point:
import matplotlib.pyplot as plt
import seaborn as sns
fig, (ax1, ax2) = plt.subplots(ncols=2)
tips = sns.load_dataset("tips")
sns.scatterplot(ax=ax1, data=tips, x="total_bill", y="tip")
sns.scatterplot(ax=ax2, data=tips, x="total_bill", y="tip", edgecolor='None')

Legend not dispalyed [duplicate]

This question already has answers here:
Adding a legend to PyPlot in Matplotlib in the simplest manner possible
(6 answers)
Closed 3 years ago.
I am trying to draw a simple graph in python using matplotlib.I am not able to use pyplot.legend() method to display legend.Please help me.
I looked on the net and found a simple code which says it works:
import numpy as np
import matplotlib.pyplot as plt
# generate random data for plotting
x = np.linspace(0.0,100,50)
y = np.random.normal(size=50)
plt.plot(x,y)
# call method plt.legend
plt.legend(['line plot 1'])
plt.show()
from the site
http://queirozf.com/entries/matplotlib-examples-displaying-and-configuring-legends.
My code is below:
import matplotlib.pyplot as plt
%matplotlib inline
views = [123,56,64,54,223,5523]
days = range(1,7)
plt.xlabel("Days")
plt.ylabel("Views")
plt.title("You Tube views")
plt.legend(["Youtube views"])
plt.plot(days,views)
plt.show()
Write plt.legend(["Youtube views"]) next plt.plot(days,views)
plt.xlabel("Days")
plt.ylabel("Views")
plt.title("You Tube views")
plt.plot(days,views)
plt.legend(["Youtube views"])
plt.show()

How to remove all padding in matplotlib subplots when using images [duplicate]

This question already has answers here:
How to combine gridspec with plt.subplots() to eliminate space between rows of subplots
(1 answer)
How to remove the space between subplots in matplotlib.pyplot?
(5 answers)
Closed 3 years ago.
When creating subplots with matplotlib i cannot get tight layout where there would not be any spaces between subplot items.
import numpy as np
import matplotlib.pyplot as plt
fig, axes = plt.subplots(3, 3, figsize=(10,10),gridspec_kw = {'wspace':0, 'hspace':0})
for i, ax in enumerate(axes.ravel()):
im = ax.imshow(np.random.normal(size=200).reshape([10,20]))
ax.axis('off')
plt.tight_layout()
Subplots would consist of images. Seems like there is way to do this when you are not using images. So i assume, there is some configuration about imshow().
I would like to keep aspect ratio of images, but make subplots compact as possible.
this is what i get now, but as you can see, there is a lot of row padding
https://imgur.com/a/u4IntRV

cannot show label in PyPlot called from Julia [duplicate]

This question already has an answer here:
matplotlib label doesn't work
(1 answer)
Closed 4 years ago.
I cannot render the label in PyPlot called from Julia. Does anyone know why?
using PyPlot
x = 0:0.1:10
y = x.^2
plot(x, y, label="label")
The above code renders only the plot without the label. I tried this both at Julia1.0 and Julia0.7, but the results were the same. The working environment is Ubuntu16.04, and I have already installed matplotlib for Python3 in my computer via pip.
As has been mentioned in the comments, to actually render a legend you have to call legend().
using PyPlot
x = 0:0.1:10
y = x.^2
plot(x, y, label="label")
legend()
This is not Julia specific but works the same way in Python.

Saving a barplot in matplotlib.pyplot [duplicate]

This question already has answers here:
Matplotlib (pyplot) savefig outputs blank image
(5 answers)
Closed 5 years ago.
I have two python lists - a (entries are strings) and b (numerical). I plot them with the following snippet (works perfectly) -
import matplotlib.pyplot as plt
plt.bar(names, values)
plt.suptitle('Average Resale Price (SGD) vs Flat Model')
plt.xticks(rotation='82.5')
plt.show()
Now I try to save the above figure -
plt.savefig('foo.png',dpi=400)
However I end up getting a white figure! How do I save the barplot ?
It's not hard. Try to put plt.savefig('foo.png',dpi=400) before plt.show():
import matplotlib.pyplot as plt
names=['alex', 'simon', 'beta']
values=[10,20,30]
plt.bar(names, values)
plt.suptitle('Average Resale Price (SGD) vs Flat Model')
plt.xticks(rotation='82.5')
plt.savefig('foo.png',dpi=400)
plt.show()