

In this example, we are changing the color of y-axis tables to blue color, and x-axis tables to orange color rotated them to 45 degrees. Plt.bar(sales_data.index, sales_data,Ĭolor = 'rgbycm', edgecolor = 'green') Format Axis Labels of a bar chart # Or use the first letter of a color in the list items For example, ax.bar(sales_data.index, sales_data, Here, we used the colors names as the list items. import pandas as pdĬolors = Īx.bar(sales_data.index, sales_data, Next, we used an edgecolor argument to change the the Python bar chart border color to green. If there are more than 6, then these colors will repeat for the other ones. It means, if there are 6, then the default color will replace these colors. Use color argument to change the colors of the rectangles, and edgecolor argument to change the color of the edges. import pandas as pdĪx.barh(sales_data.index, sales_data)


Next, we changed the xlabel and ylabel to changes the axis names. In this example, we replaced the actual function with the barh function to draw a horizontal bar chart. The matplotlib library provides a barh function to draw or plot a horizontal bar chart in Python. To use the same, try plt.xlim(0, 10) or something like that. Similarly, you can limit the axis values of the X-axis using the xlim method. Sales_data = df.groupby('Region')].sum()Īx.bar(sales_data.index, sales_data) Here, we changed the starting value from 0 to 50000 and end value from 2500000 to 3000000. There is a ylim method in pyplot bar function that will limit or change the y-axis values. Plt.show() Limit Y-axis values of Python bar plot Plt.setp(labels, rotation = 45, horizontalalignment = 'right')

Print(sales_groupedby_region.sort_values(by = ))Īx.bar(sales_groupedby_region.index, sales_groupedby_region)įrom the above Python bar chart screenshot, you can see that the x-axis values merged so that we are unable to identify them. It means the below matplotlib bar chart will display the Sales of all regions. Next, we plot the Region name against the Sales sum value. And next, we are finding the Sum of Sales Amount. As you can see from the below Python code, first, we are using the pandas Dataframe groupby function to group Region items. In this example, we are using the data from the CSV file in our local directory. Plt.show() Python matplotlib Bar chart from CSV file Plt.grid(color = 'red', alpha = 0.3, linestyle = '-', linewidth = 2) If you want to display grid lines in your Python bar chart, use the grid() function available in the pyplot.
