serv-inc
serv-inc

Reputation: 38177

Reproduce gnuplot's with boxes in matplotlib

Is there a way to reproduce the format of gnuplot's with boxes in matplotlib? The closest so far seems to be .step.

In Gnuplot:

import Gnuplot
gplt = Gnuplot.Gnuplot()
data = Gnuplot.Data(zip(range(3), range(3)), with_="boxes")
gplt.plot(data)

In Pyplot:

import matplotlib.pyplot as plt
plt.step(range(3), range(3))

produces (left for Gnuplot)

gnuplot box drawing matplotlib steps

How can the boxes be drawn to the x-axis each time in pyplot?

Upvotes: 0

Views: 105

Answers (1)

DavidG
DavidG

Reputation: 25362

You can simply create a bar chart with no space between the bars and setting fill=False:

import matplotlib.pyplot as plt

plt.bar(range(3), range(3), fill=False, width=1)
plt.show()

enter image description here

Upvotes: 1

Related Questions