Giter Site home page Giter Site logo

arnab132 / graph-plotting-python Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 14 KB

Graph Plotting Implementation using Python

Home Page: https://github.com/arnab132/Graph-Plotting-Python/

Python 100.00%
graph-plot python-ploting matplotlib-pyplot matplotlib graph matplotlib-python bar-plot bargraph histogram pie-chart scatter-plot

graph-plotting-python's Introduction

Graph Plotting using Python

This series will introduce you to graphing in python with Matplotlib, which is arguably the most popular graphing and data visualization library for Python.

Installation

Easiest way to install matplotlib is to use pip. Type following command in terminal:

pip install matplotlib

Customization of Plots

image

As you can see, we have done several customizations like

setting the line-width, line-style, line-color. setting the marker, marker’s face color, marker’s size. overriding the x and y axis range. If overriding is not done, pyplot module uses auto-scale feature to set the axis range and scale.

Bar Chart

Here, we use plt.bar() function to plot a bar chart.

image

x-coordinates of left side of bars are passed along with heights of bars.

you can also give some name to x-axis coordinates by defining tick_labels

Histogram

Here, we use plt.hist() function to plot a histogram.

image

frequencies are passed as the ages list. Range could be set by defining a tuple containing min and max value. Next step is to “bin” the range of values—that is, divide the entire range of values into a series of intervals—and then count how many values fall into each interval. Here we have defined bins = 10. So, there are a total of 100/10 = 10 intervals.

Scatter Plot

image

Here, we use plt.scatter() function to plot a scatter plot. Like a line, we define x and corresponding y – axis values here as well. marker argument is used to set the character to use as marker. Its size can be defined using s parameter.

Pie Chart

Here, we plot a pie chart by using plt.pie() method.

image

First of all, we define the labels using a list called activities. Then, portion of each label can be defined using another list called slices. Color for each label is defined using a list called colors. shadow = True will show a shadow beneath each label in pie-chart. startangle rotates the start of the pie chart by given degrees counterclockwise from the x-axis. explode is used to set the fraction of radius with which we offset each wedge. autopct is used to format the value of each label. Here, we have set it to show the percentage value only upto 1 decimal place.

Plotting curves of given equation

image

Here, we use NumPy which is a general-purpose array-processing package in python.

To set the x – axis values, we use np.arange() method in which first two arguments are for range and third one for step-wise increment. The result is a numpy array. To get corresponding y-axis values, we simply use predefined np.sin() method on the numpy array. Finally, we plot the points by passing x and y arrays to the plt.plot() function.

So, in this repository, I have discussed various types of plots we can create in matplotlib.

graph-plotting-python's People

Contributors

arnab132 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.