04pallav
9/11/2017 - 10:29 PM

plt plotting

plt plotting

dataset1 = randn(100)
plt.plot(dataset1,linewidth=1.0, linestyle="-",color='red') #by default takes LINE
##### for simple plotting

x=np.arange(0,10,0.1)
plt.plot(x,np.sin(x),label='sin') # SCATTERPLOT connected by lines
#see exact scatter plot code below
#plt.plot(x,y,label='label of y')

'--r' dashed red
'-g' continous green

colors are b,g,r,c,m,y,k,w

plt.hist(dataset1,alpha=0.1)
plt.hist(dataset1,color='red',alpha=0.1,bins=50)
plt.hist(dataset1,color='green',alpha=0.5,normed=True)
#note histogram needs only x to plot
#HISTOGRAM IS JUST A FREQUENCY DISTRIBUTION ON ANY SERIES
# Set alpha=0.5 for transperancy #mostly can be used in many plots
#normed=True normalises meaning brings values between 0 and 1

plt.pie(dataset1)
df1.plot(autopct='%.2f', fontsize=20, figsize=(6, 6),kind='pie') #PREFERRED
#plt.pie(series)

plt.bar(x, y1, bottom=5, color = 'r') #use bottom argument to make bar plots
#use this to make stacked plots

plt.scatter(x,y) #scatter plots between x and y

#General plt commands
plt.figure(figsize=(8,6), dpi=80) #creates a NEW figure of size 8X6
#8 is length and 6 is height
plt.subplot(121) # 1 row 2 column 1 position of plot
#you are dividing the figure which was created in 1*2 and get the first position
#now plot
plt.subplot(122)
#now plot

plt.suptitle("Sum of the Basis Functions") #gives main titile to plot
plt.yticks([]) #Get rid of y‐tick marks
plt.xticks(np.linspace(‐4,4,9,endpoint=True))
plt.xticks([‐np.pi, ‐np.pi/2, 0, np.pi/2, np.pi],[r'$‐\pi$', r'$‐\pi/2$', r'$0$', r'$+\pi/2$', r'$+\pi$']) #rename plot tick labels
plt.gca().get_xticklabels()[1].set_color("red") #give particular colors to ticks
plt.xticks(rotation='vertical')
plt.xlim(0,1) #used to give set xlim in graph # subsets your graph not scales
plt.xlabel('xlabel') # giving labels to axes
plt.legend(loc='upper left', frameon=False)
# label= HAS TO BE ADDED TO THE PLOT COMMAND FOR THIS TO WORK
plt.axis() #gives xmin,xmax,ymin,ymax for the axes
plt.axis([-1, 1, -10, 10]) # sets xmin,xmax,ymin,ymax for setting axis limits
plt.axhline(4) #will add a horizontal line at 4
plt.grid() #toggles grid on and off
fig = plt.figure(figsize=(10,8))
fig.text(1,0.25,"my text",fontsize=20)