Unable to get a histogram to display individual silos with vertical lines

Annoying weird problem, and I have not yet been able to find a solution on this site (although the question has appeared)

I am trying to make a histogram where the bunkers have a β€œbar style” where vertical lines separate each bit, but no matter what I change the histtype constructor, I get a filled histogram step.

Here is my code. Note. I am using jupyter notebook installed via anaconda with python version 2.7.6.

import numpy as np import matplotlib.pyplot as plt x = np.random.rand((100)) bins = np.linspace(0, 2, 40) plt.title('Relative Amplitude',fontsize=30) plt.xlabel('Random Histogram') plt.ylabel('Frequency',fontsize=30) plt.hist(x, bins, alpha=0.5, histtype='bar') plt.legend(loc='upper right',fontsize=30) plt.xticks(fontsize = 20) plt.yticks(fontsize = 20) plt.show() 

This and I get a diagram filled with steps, with no vertical lines separating the columns. What annoys me is that I didn’t have this problem a while ago, something has clearly changed, and I don’t know what. I tried histype = 'barstacked'. Thank you for your help.

enter image description here

+11
source share
1 answer

Using your example:

 import numpy as np import matplotlib.pyplot as plt x = np.random.rand((100)) bins = np.linspace(0, 2, 40) plt.title('Relative Amplitude',fontsize=30) plt.xlabel('Random Histogram') plt.ylabel('Frequency',fontsize=30) plt.hist(x, bins, alpha=0.5, histtype='bar', ec='black') plt.legend(loc='upper right',fontsize=30) plt.xticks(fontsize = 20) plt.yticks(fontsize = 20) plt.show() 

Which produces the following image:

enter image description here

The key difference is the use of the ec key argument. This is short for edgecolor. The plt.hist documentation says that in addition to all of the keyword arguments listed, plt.hist also accepts keyword arguments for the Patch initializer. edgecolor is one of these key arguments. This is why this is not explicitly stated in the documentation for plt.hist . All the columns in the graph are a separate Patch object, so you say that you want all edgecolor be drawn with a black outline (or edgecolor in the matplotlib language).

+24
source

Source: https://habr.com/ru/post/1015385/


All Articles