Making Plot of Numpy Array Values
<p>I have a large numpy.ndarray that I want to make a plot of, where the x axis has to do with the values in the array and the y axis shows how often that value has appeared in the array.  To be clear, I don't care about the order of the data in the array or if their order gets screwed up, I just want to take the numbers, bin them, and then plot them.</p>

<p>Steps I have so far that I want to do, each separate in my Jupyter notebook</p>

<ul>
<li><p>Open/read my array (it's 1024x1024, so quite large)- step done</p></li>
<li><p>Convert array into list- done</p></li>
<li><p>Spit out null values in array... currently not working</p></li>
<li><p>Bin data to count values... really lost here</p></li>
<li><p>Scatter plot- trimmed vs count- this part will be fine once the previous two work, matplotlib and I get along</p>

<p>import numpy as np</p>

<p>import matplotlib.pyplot as plt</p>

<p>scidata = np array of data that's 1024x1024</p>

<p>lsci = []</p>

<p>for r in range(1024):</p>

<pre><code>scilist = scidata[r,:].tolist()

lsci.extend(scilist)

trimmed = lsci
</code></pre>

<p>for item in lsci: </p>

<pre><code>  if 12.58 &lt;= i== 12.59: #the null value I don't want is in this range

  r.remove(item)
</code></pre></li>
</ul>

<p>I'm sorry, I wish I had more, but this is where things get dicey for me and I'm kinda ashamed to post what I've tried and failed at because most are dead ends.  The only real solution I've thought of is binning the data... but that won't work for a scatter plot because the length of the two lists won't be the same and a histogram isn't what I want as my final product anyway.  So is there another approach I can be using for this that I'm unaware of? (I feel like there's some chunk of coding knowledge that I just never learned- surely I'm not the first person to want to do this.) Thanks!</p>

<p>Edit: Sorry, all my code isn't showing up as code even though I put four spaces...</p>

<p>'Binning' is definitely a histogram feature but I get the impression you want a simple pivot table.  How about:</p>

<ol>
<li>Remove undesired value</li>
<li>Convert your numpy array to dataframe</li>
<li>Create pivot table from dataframe</li>
<li>Plot results</li>
</ol>

<hr>

<pre><code>import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
% matplotlib inline

a = np.random.randint(10, size=100)   # array([3, 0, 3, 8, 1, 9, 1, 8,...])
exclude_value = 3  # change as required
a_new = [item for item in a if item != exclude_value] # new list without exclude value

df = pd.DataFrame(a_new).pivot_table(columns=0, aggfunc='size')

x = df.index.values
y = df.values
plt.bar(x,y)

plt.xticks(x)
plt.show()
</code></pre>

<hr>

<p>OUTPUT:</p>

<p><em>(note how one value has been excluded, in this case 3)</em>
<a href="http://i.stack.imgur.com/wX2Tb.png" rel="nofollow"><img src="http://i.stack.imgur.com/wX2Tb.png" alt="enter image description here"></a></p>

python arrays numpy matplotlib