0

I have to realize a histogram using matplotlip and plotly. But I am stuck because there are so many options available and with so don't manage to have a proper histogram with all the online tutorials. My data is a matrix of two columns and 20000 rows. I use those commands, but it didn't work.

here is my code:

with open('rmsd.dat') as f:
       v = np.loadtxt(f, delimiter= ' ')
plt.hist(v, bins=100)
plt.xlabel("G-r0")
plt.ylabel('# of stars')
plt.title("RMSD histogramm")

plt.show()

In a second time the histogram has to be horizontal and near another plot using the same data I tried to use matplotlib and plotly but it was a big mess

that all

2
  • 3
    sorry, how is your data? Is one column your values and second column your frequency? When you do plt.hist(v) it calculates the histogram from your array. May be you should look into histogram2d docs.scipy.org/doc/numpy/reference/generated/…` Commented Mar 23, 2017 at 15:54
  • 2
    "it didn't work" is not useful. Please read stackoverflow.com/help/how-to-ask and include the errors you see or what you see and what you expect to see. Commented Mar 23, 2017 at 16:04

1 Answer 1

1

Your data has two columns, so you must to indicate which column you want to plot.

import matplotlib.pyplot as plt
data[:,0] #shape (3000,2)
plt.hist(data[:,0],bins=100)

Example1

Or horizontal:

plt.hist(data[:,0],bins=100,orientation='horizontal')

If I just use plt.hist(data,bins=30) it will appear like a simple bar plot.

Example2

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.