Specify Saved Image Dimensions in Seabron FacetGrid [duplicate] - matplotlib

This question already has answers here:
How to change the figure size of a seaborn axes or figure level plot
(13 answers)
How to change a figure's size in Python Seaborn package
(7 answers)
Closed 4 years ago.
I cannot override the Seaborn defaults on image size.
I would think that the plt.figure(figsize=(8.5,11)) would specify the actual dimensions of the image saved. It does not. The dimensions of the saved file are 4.5" by 2.25". That is different from 8.5" x 11".
import pandas as pd
import seaborn as sb
from matplotlib import pyplot as plt
plt.figure(figsize=(8.5,11))
df = sb.load_dataset('tips')
g = sb.FacetGrid(df, col = "time")
g.map(plt.hist, "tip")
plt.savefig("size_test_plot.jpg")
plt.show()
What is the solution?

Related

How do I add custom calculated error bars to seaborn bar plots? [duplicate]

This question already has answers here:
How to plot errorbars on seaborn barplot
(1 answer)
Seaborn: Making barplot by group with asymmetrical custom error bars
(1 answer)
How to add error bars on a grouped barplot from a column
(4 answers)
Closed last month.
The situation: university gave us an Excel document. We have a table, just write in our data and we get some tables and plots out. I think the plots are ugly and since I need it for a public presentation, I wanted to redo the plot with seaborn. I managed to actually plot the bars. The only trouble now: I can't add the variance to the bars.
This is my table:
Label,Mean,Error
"Appearance",2.50,0.45
"Functionality",1.90,0.32
"Predictability",2.740,0.52
"Inefficiency",1.701,2.41
This is my code:
import seaborn as sb
import matplotlib.pyplot as plt
import pandas as pd
if __name__ == '__main__':
csv = pd.read_csv('res.csv')
sb.set_theme(style = "darkgrid")
sb.barplot(x = "Mean", y = "Label", data = csv, errorbar="sd")
# plt.savefig('myfile.png', bbox_inches="tight")
plt.show()

'numpy.ndarray' object has no attribute 'hist while using Seaborn [duplicate]

This question already has answers here:
How to plot in multiple subplots
(12 answers)
seaborn is not plotting within defined subplots
(1 answer)
Closed 7 months ago.
I am using the code below to plot a histogram.
Does anyone know why I am facing this error: 'numpy.ndarray' object has no attribute 'hist
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
fig, axes = plt.subplots(2,2)
sns.distplot(minimum_1 , color="dodgerblue", ax=axes[0], axlabel='Ideal')
sns.distplot(minimum_2 , color="deeppink", ax=axes[1], axlabel='Fair')
sns.distplot(minimum_3 , color="gold", ax=axes[2], axlabel='Good')
sns.distplot(minimum_4 , color="gold", ax=axes[3], axlabel='Good')

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()

jupyter qtconsole, matplotlib: scale displayed image to window width [duplicate]

This question already has answers here:
How do I change the size of figures drawn with Matplotlib?
(14 answers)
Closed 4 years ago.
I'd like to scale images that I display in jupyter qtconsole to window width.
All images are shown just in the size of 5x5cm, nevertheless how large they really are. Tried that with a 1k by 1k image and a 7,7k by 7,7k image. Shows the same.
I don't think it's a matter of astropy but matplotlib or jupyter qtconsole.
Couldn't find anything on docu of matplotlib or jupyter qtconsole.
code is:
`from astropy.io import fits
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.colors import LogNorm
img_file = 'rxcj0920.1+8602.fits' # 1kx1k
hdu_list = fits.open(img_file)
img_data = hdu_list[0].data
plt.imshow(img_data, cmap='gist_heat', origin='lower', norm=LogNorm(), vmin=400, vmax= 65e3), plt.colorbar()`
Does
import matplotlib
matplotlib.rcParams['figure.figsize'] = (10.,10.)
have any effect?

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()