samedi 5 avril 2014

Python 2.7 - ajouter du texte dans les bacs d'histogramme dans wxpython - Stack Overflow


How to write text inside bins(bars) of histograms in wxpython?


    import csv
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.figure import Figure
data1 = np.random.normal(5.0,3.0,1000)
with open('test.csv', 'wb') as f:
writer = csv.writer(f)



plt.hist(data1)
plt.show()



You can't write text inside the bins directly. This is because the bins are simple Pactch objects.
However, have no despair! There is a path you can go to achieve this:



  • iterate over bins, get their boundaries

  • create a text label

  • place it in the correct boundaries


To obtain the bin boundaries see my answer here: How to color bars who make up 50% of the data?



How to write text inside bins(bars) of histograms in wxpython?


    import csv
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.figure import Figure
data1 = np.random.normal(5.0,3.0,1000)
with open('test.csv', 'wb') as f:
writer = csv.writer(f)



plt.hist(data1)
plt.show()


You can't write text inside the bins directly. This is because the bins are simple Pactch objects.
However, have no despair! There is a path you can go to achieve this:



  • iterate over bins, get their boundaries

  • create a text label

  • place it in the correct boundaries


To obtain the bin boundaries see my answer here: How to color bars who make up 50% of the data?


0 commentaires:

Enregistrer un commentaire