Plotting Normal Graph
-
pyplot.plot()
function: If you callplot()
one after another, Next graph will be printed on same graph window.
plt.plot(x_axis_column, y_axis_column)
plt.show()
- Labeling Graph Label gives different names to Graph as we wanted it. Legend: Area that describe graph elements. This function have attributes for styling and locating legend on graph screen
plt.plot(x_axis_column, y_axis_column, label='Label Name')
plt.title('Title of Graph')
plt.ylabel('Ylabel')
plt.xlabel('Ylabel')
plt.legend()
plt.show()
-
.text()
for adding text Annotation to graph: Main Documentation for further details
plt.text(xPosition,yPosition,'Text')
Be careful while putting positional co-ordinates. Don't set it out of range.
- Styling Graph:
In
.plt.plot()
we have attributes likecolor
,linestyle
,marker
. There are multiple default styles provided by matplotlib to try on to your graphs.
Plotting Scatter Plot
- Only change from
.plot
to.scatter
And Styling can be applied same as normal Graph
plt.scatter(x_axis_column, y_axis_column, color = 'red')
- You can add Crazy styling with different Background image. Resource here
Plotting Bar Graph
Can you guess how to do that?
plt.bar()
? Yes Exactly!
plt.bar(x_axis_column, y_axis_column)
Plotting histogram
First Question: What's difference between Bar graph and histogram?
Histogram: display the frequency of numerical data, It means in given column of database what is the frequency of particular number.
It contains non-discrete values.
Bar graph: compare different categories of data. discrete values can work.
Much clear difference here
Now Actual Plotting:
plt.hist(column_data_for_histogram, bins=50, range = (5,35))
Changing Value of bins
Bins are number of columns or towers in the histogram. Default value of these bins is 10. We can modify in the code.
Defining Range of histogram
Manually selecting range for histogram for where to start and end.
Top comments (0)