# horizontal bar graph matplotlib

Bar charts is one of the type of charts it can be plot. import matplotlib.pyplot as plt import numpy as np # Fixing random state for reproducibility np. Later, you’ll also see how to plot a horizontal bar chart with the help of the Pandas library. In that case, you can use the code below in order to create the horizontal bar chart with both the price and quantity: As you can see, the price is represented in orange, while the quantity represented in blue: You can learn more about plotting charts by visiting the Matplotlib Documentation. For example, let’s use the data below to plot the chart: The above data can be captured in Python using lists: If you run the code in Python, you’ll get the following lists: You can then plot the chart using this syntax: Notice that the ‘Product‘ is displayed on the y_axis, while the ‘Quantity‘ is displayed on the x_axis: You can further style the chart by including the following syntax: So the complete code would look as follows: You can plot the same bar chart with the help of the Pandas library: Once you run the code, you’ll get the same bar chart: Let’s say that you also want to capture the ‘Price‘ (in addition to ‘Quantity’) associated with the product. The method bar() creates a bar chart. Related course: Matplotlib Examples and Video Course. For example, let’s use the data below to plot the chart: Steps to Create a Horizontal Bar Chart using Matplotlib Step 1: Gather the data for the chart. rcdefaults fig, ax = plt. To do so just call the barh() function instead of bar(). You might like the Matplotlib gallery. In this tutorial we’ll be making a Horizontal Bar Graph with Matplotlib in Python. Here is a tip to turn your barplot horizontal with matplotlib. Matplotlib may be used to create bar charts. random. import matplotlib.pyplot as plt import numpy as np # Fixing random state for reproducibility np. There are many different variations of bar charts. Thank you for visiting the python graph gallery. More on bar charts You can compare two data series using this Matplotlib code: import numpy as np import matplotlib.pyplot as plt # data to plot n_groups = 4 Next, we changed the xlabel and ylabel to changes the axis names. Here is a simple template that you can use to create a horizontal bar chart using Matplotlib: Later, you’ll also see how to plot a horizontal bar chart with the help of the Pandas library. We feed it the horizontal and vertical (data) data. rcdefaults fig, ax = plt. In this example, we replaced the bar function with the barh function to draw a horizontal bar chart. random. Example Bar chart. seed (19680801) plt. Python matplotlib Horizontal Bar Chart. The matplotlib library provides a barh function to draw or plot a horizontal bar chart in Python. So how do you use it? Horizontal bar chart¶ This example showcases a simple horizontal bar chart. seed (19680801) plt. We also need to reverse our lists, otherwise January will be at the very bottom. How to Create a Horizontal Bar Chart using Matplotlib. The program below creates a bar chart. Horizontal bar chart¶ This example showcases a simple horizontal bar chart. Related course ... Bar chart horizontal. All Rights Reserved by Suresh, Home | About Us | Contact Us | Privacy Policy. Here we’ll do a similar example to the regular Bar Graph, but instead we’ll flip the axes, and use Matplotlib’s Axes object.