Here in this post we will see how we can plot vertical bar graph using Plotly library in Python. As a data visualization expert, you should know how to implement types of charts used frequently in the industry. Also, its important that we should have an idea how we can leverage the power of all the import packages available in python.
In our previous posts we have shared how you can create the charts using Matplotlib library. Let’s now see how we can use plotly to create beautiful visualizations.
Let’s see the code below:
Below code will import the Pandas and Plotly package that we will need to plot the vertical bar graph. Also, we import the data set which contain two columns namely Name and Marks.
import pandas as pd import plotly.express as px Data = pd.read_excel(r"C:\Users\WeirdGeek\Desktop\WG_Test.xlsx") Data.head()
This is how the data looks like:
To plot the charts, its just a two lines of code. In first line we passed the data frame name along with the columns we want to plot on x and y axis. in second line, we just add a code to show the plot.
fig = px.bar(Data, x='Name', y="Marks") fig.show()
Below is the chart we got from above code:
To get more detailed knowledge about types of Charts, you can check the official Plotly website. Also if you want to explore more codes/posts related to same topic on our website, then you can find it here.
If you have any questions or if you need any help please get in touch with me using the comment section below.
Leave a Reply