0

currently I have a program that takes data and makes a histogram out of it, I know how to change the labels and stuff, but is there a way to make x-axis display the number range more frequently (badly worded I'll just give an example):so right now on the x-axis is shows the number values in increments of 5, but how can I make it show up in like increments of 2 or 1 or 3.

Current code:

#!/usr/bin/python
import operator
import matplotlib.pyplot as plt
import numpy as np

l=[]
with open("testdata") as f:
    line = f.next()
    f.next()# skip headers
    nat = int(line.split()[
    print nat

    for line in f:
        if line.strip():
            l.append(map(float,line.split()[1:]))  

    b = 0
    a = 1

distances = []
for b in range(53):
    for a in range(b+1,54):
        vector1 = (l[b][0],l[b][1],l[b][2])
        vector2 = (l[a][0],l[a][1],l[a][2])

        x = vector1
        y = vector2
            vector3 = list(np.array(x) - np.array(y))

        dotProduct = reduce( operator.add, map( operator.mul, vector3, vector3))

        dp = dotProduct**.5

        distances.append(dp)

    num_bins = 200 # <- number of bins for the histogram
(n, bins, patches) = plt.hist(distances, num_bins) 
plt.title('Histogram')
plt.xlabel('Distance')
plt.ylabel('Frequency')

plt.show()

1 Answer 1

1
label_positions = np.arange(start, end, step, endpoint=True)
plt.xticks(label_positions)
Sign up to request clarification or add additional context in comments.

2 Comments

By the way is there also a way to make the actual value of each bar appear on top of the bars?
you might visit the matplotlib example matplotlib.org/examples/api/barchart_demo.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.