Jake
Jake

Reputation: 27

Remove xtick intervals matplotlib

I am attempting to make a sorting algorithm visualization in python. I decided to use matplotlib to do so. I have an array with 495 randomly generated numbers to be randomly plotted on my bar chart as a starting point for the algorithm. I am running into an issue with the chart itself where the plots seem to be uniformly separated on the x axis. How can I get rid of this?

import matplotlib.pyplot as plt
import numpy as np


def main():
    start_array(5,501,1000)
    graph()

def graph():
    xpos = np.arange(len(start_list))
    plt.figure(figsize=(13,13))
    plt.axis("off")
    plt.bar(xpos, start_list,width=0.3,align="center")
    plt.show()
    print(start_list)

def start_array(range1,range2,size):
    global start_list
    start_list = np.random.randint(range1,range2,size=size)

main()

enter image description here

Upvotes: 0

Views: 180

Answers (1)

Sheldon
Sheldon

Reputation: 4653

This is just a display problem, as explained in this answer.

You can solve it by increasing the width of your individual bars in:

plt.bar(xpos, start_list,width=0.3,align="center")

Upvotes: 1

Related Questions