1

I would like to plot the softmax probabilities for a neural network classification task, similar to the plot below

However most of the code I've found on SO and the doc pages for matplotlib are using histograms.

Examples:

plotting histograms whose bar heights sum to 1 in matplotlib

Python: matplotlib - probability mass function as histogram

http://matplotlib.org/gallery.html

But none of them match what I'm trying to achieve in that plot. Code and sample figure are highly appreciated.

example softmax plot

Community
  • 1
  • 1
Sam Hammamy
  • 10,819
  • 10
  • 56
  • 94

1 Answers1

2

I guess you are just looking for a different plot type. Adapted from here:

# Import 
import numpy as np
import matplotlib.pyplot as plt

# Generate random normally distributed data
data=np.random.randn(10000)

# Histogram
heights,bins = np.histogram(data,bins=50)

# Normalize
heights = heights/float(sum(heights))
binMids=bins[:-1]+np.diff(bins)/2.
plt.plot(binMids,heights)

Which produces something like this:

enter image description here

Hope that is what you are looking for.

Community
  • 1
  • 1
alexblae
  • 746
  • 1
  • 5
  • 13