1

For example i have next situation: enter image description here

but i want that width for each bin was bigger.
something like this: enter image description here

so target is just adjust width for each bin

code is :

    x_axis_values = []
    for i in range(-50, 51, 1):
        x_axis_values.append(i)
    pl.xticks((np.arange(-50, 50, 1)), rotation=45, fontsize=5)
    pl.yticks(fontsize=10)
    pl.hist(deltas, bins=x_axis_values, color='red', edgecolor='black', linewidth=0.5)
    pl.title('Histogramm md_latency_is_bigger|0|main_latency_is_bigger')
    pl.xlabel('deltas value, ms')
    pl.ylabel('delta count, cnt')
    pl.ticklabel_format(axis='y', style='plain')
    pl.savefig('HISTOGRAMM.png')
    pl.show()
ditrauth
  • 111
  • 8

1 Answers1

1

See the documentation how the bins are used.

If you want to change the bin width - you could change the step size in your x-axis:

stepsize = 20

plt.figure(figsize=(20,10))

x_axis_values = []
x_axis_values = np.arange(-50, 51, stepsize)
plt.xticks((np.arange(-50, 50, 20)), rotation=45, fontsize=5)
plt.yticks(fontsize=10)
plt.hist(deltas, bins=x_axis_values, color='red', edgecolor='black', linewidth=0.5)
plt.title('Histogramm md_latency_is_bigger|0|main_latency_is_bigger')
plt.xlabel('deltas value, ms')
plt.ylabel('delta count, cnt')
plt.ticklabel_format(axis='y', style='plain')
plt.savefig('HISTOGRAMM.png')
plt.show()

producing a wider figure with bigger bins:

enter image description here

Also see this question if it helps you:


As the documentation states:

If bins is a sequence, it defines the bin edges, including the left edge of the first bin and the right edge of the last bin

So you need to create a sequence, fitting your needs. numpy.linspace and numpy.arange can be useful for that.

Helmut
  • 311
  • 1
  • 9