Hide matplotlib descriptions in jupyter notebook [duplicate] - matplotlib

This question already has answers here:
Disable the output of matplotlib pyplot
(5 answers)
Closed 6 years ago.
I am not sure what is the correct term for this, but here is what I see when I plot something:
The plots is actually what I want so see, but jupyter notebook also outputs some text: <matplotlib.axes._subplots.AxesSubplot at 0x1263354d0>, <matplotlib.figure.Figure at 0x1263353d0> which I am trying to get rid of.
After some searching, the only thing I was able to find is plt.ioff(), which didn't help me. Is there a way to get rid of the text?

You can finish the corresponding (matplotlib) line with a semicolon ;

This is a bit of a workaround, but it should work consistently:
1. Assign the plotting function to a variable (which could also be useful if you need to access some plot elements later on)
plt.figure(figsize=(3, 3))
plot = plt.plot(range(10),
[x*x for x in range(10)],
'o-')
2. Add a "pass" at the bottom of the cell (or an equivalent operation with no consequence)
plt.figure(figsize=(3, 3))
plt.plot(range(10),
[x*x for x in range(10)],
'o-')
pass
3. Add a semicolon at the end of the last statement
plt.figure(figsize=(3, 3))
plt.plot(range(10),
[x*x for x in range(10)],
'o-');

Related

How to group a Box plot by the column names of a data frame in Seaborn? [duplicate]

This question already has answers here:
Boxplot of Multiple Columns of a Pandas Dataframe on the Same Figure (seaborn)
(4 answers)
Closed 24 days ago.
I'm a beginner trying to learn data science and this is my first time using the seaborn and matplotlib libraries. I have this practice dataset and data frame :
that I want to turn into a box plot and I want the x-axis to have all of the column names and the y-axis to range from 0 - 700 but, I'm not sure what to do.
I tried using : random_variable = sms.boxplot(data = df, x = ?, y = 'TAX')
which does give me the y-axis that is close to what I am looking for but, I don't know what the x-axis should be set equal too.
I thought may I could use the keys of the dataframe but, all I got was this mess that doesn't work:
random_variable = sms.boxplot(x = df.keys(), y = df['TAX'])
I want it to look like this but, I'm really lost on how to do this:
I apologize if this is an easy fix but, I would appreciate any help.
If you just want to display your data like that go with
import seaborn as sns
sns.boxplot(data=df)

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.

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

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

How does numpy polyfit work?

I've created the "Precipitation Analysis" example Jupyter Notebook in the Bluemix Spark service.
Notebook Link: https://console.ng.bluemix.net/data/notebooks/3ffc43e2-d639-4895-91a7-8f1599369a86/view?access_token=effff68dbeb5f9fc0d2df20cb51bffa266748f2d177b730d5d096cb54b35e5f0
So in In[34] and In[35] (you have to scroll a lot) they use numpy polyfit to calculate the trend for given temperature data. However, I do not understand how to use it.
Can somebody explain it?
The question has been answered on Developerworks:-
https://developer.ibm.com/answers/questions/282350/how-does-numpy-polyfit-work.html
I will try to explain each of this:-
index = chile[chile>0.0].index => this statements gives out all the years which are indices in chile python series which are greater than 0.0.
fit = np.polyfit(index.astype('int'), chile[index].values,1)
This is polyfit function call which find out ploynomial fitting coefficient(slope and intercept) for the given x(years) and y(precipitation on year) values at index(years) supplied through the vectors.
print "slope: " + str(fit[0])
The below code simply plots the datapoints referenced to straight line to show the trend
plt.plot(index, chile[index],'.')
Perticularly in the below statement the second argument is actually straight line equation to represent y which is "y = mx + b" where m is the slope and b is intercept that we found out above using polyfit.
plt.plot(index, fit[0]*index.astype('int') + fit[1], '-', color='red')
plt.title("Precipitation Trend for Chile")
plt.xlabel("Year")
plt.ylabel("Precipitation (million cubic meters)")
plt.show()
I hope that helps.
Thanks, Charles.

matplotlib: working with range in x-axis

I'm trying to do a basic line graph here, but I can't seem to figure out how to adjust my x axis.
And here is the error I get when I try adjusting my range.
from pylab import *
plot ( range(0,11),[9,4,5,2,3,5,7,12,2,3],'.-',label='sample1' )
plot ( range(0,11),[12,5,33,2,4,5,3,3,22,10],'o-',label='sample2' )
xlabel('x axis')
ylabel('y axis')
title('my sample graphs')
legend(('sample1','sample2'))
savefig("sampleg.png",dpi=(640/8))
show()
File "C:\Python26\lib\site-packages\matplotlib\axes.py", line 228, in _xy_from_xy
raise ValueError("x and y must have same first dimension")
ValueError: x and y must have same first dimension
I want my range to be a list of strings: ["12/1/2007","12/1/2008", "12/1/2009","12/1/2010"]
Any suggestions?
Honestly, I found the code online and was trying to rewrite it to properly understand it. I think I'm going to start from scratch so that I know what I'm doing but I need help on where to start.
I posted another question which explains what I want to do here:
Using PyLab to create a 2D graph from two separate lists
range(0,11) should be range(0,10).
In addition to Steve's observation: If your points are always some y-value at the same consecutive integer x's, matplotlib makes the range even implicit.
plot([9,4,5,2,3,5,7,12,2,3],'.-',label='sample1')