1

I have a list. Index of list is degree number. Value is the probability of this degree number.

It looks like, x[ 1 ] = 0.01 means, the degree 1 's probability is 0.01.

I want to draw a distribution graph of this list, and I try

hist = plt.figure(1)
plt.hist(PrDeg, bins = 1)
plt.title("Degree Probability Histogram")
plt.xlabel("Degree")
plt.ylabel("Prob.")
hist.savefig("Prob_Hist")

PrDeg is the list which i mention above.

But the saved figure is not correct.

The X axis value becomes to Prob. and Y is Degree ( Index of list ) enter image description here

How can I exchange x and y axis value by using pyplot ?

1
  • Your histogram (except for the use of a single bin) looks quite an histogram to me... Ordinates are counts of items in bins (possibly normalized) and in abscissa you have the random variable. Commented Nov 22, 2014 at 17:08

1 Answer 1

1

Histograms do not usually show you probabilities, they show the count or frequency of observations within different intervals of values, called bins. pyplot defines interval or bins by splitting the range between the minimum and maximum value of your array into n equally sized bins, where n is the number you specified with argument : bins = 1. So, in this case your histogram has a single bin which gives it its odd aspect. By increasing that number you will be able to better see what actually happens there.

The only information that we can get from such an histogram is that the values of your data range from 0.0 to ~0.122 and that len(PrDeg) is close to 1800. If I am right about that much, it means your graph looks like what one would expect from an histogram and it is therefore not incorrect.

To answer your question about swapping the axes, the argument orientation=u'horizontal' is what you are looking for. I used it in the example below, renaming the axes accordingly:

import numpy as np
import matplotlib.pyplot as plt

PrDeg = np.random.normal(0,1,10000)
print PrDeg

hist = plt.figure(1)
plt.hist(PrDeg, bins = 100, orientation=u'horizontal')
plt.title("Degree Probability Histogram")
plt.xlabel("count")
plt.ylabel("Values randomly generated by numpy")
hist.savefig("Prob_Hist")

plt.show()
Sign up to request clarification or add additional context in comments.

Comments

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.