Issue
I would like to make a bar plot in matplotlib, but instead of bars I would like it to have lines (see picture at the bottom please for an example) It is from this paper: https://arxiv.org/abs/1907.10529
When trying to search for the solution, I only find tutorials or posts about how to plot a line in a bar graph, but that is not what I want.
Does somebody know the correct term I should use when searching for this? Any help is appreciated :)
Solution
you can play with line width and alpha values to achieve what you want. Note also you need to take care of the ticks values. considering the values where:
[0.22, 0.17, 0.13, 0.10, 0.08, 0.07, 0.065, 0.06, 0.055, 0.05]
You can do the following:
import matplotlib.pyplot as plt
values = [0.22, 0.17, 0.13, 0.10, 0.08, 0.07, 0.065, 0.06, 0.055, 0.05]
plt.figure()
ticks = []
# tip from Rabinzel to use 1 in enumerate instead of adding +1 to num
for num, value in enumerate(values, 1):
plt.plot([num, num],[0, value], lw=5, alpha=0.4, c='b')
plt.scatter(num, value,c='b')
ticks.append(num)
plt.xlabel("Span Length (# of Words)")
plt.ylabel("Sampling Probability")
plt.xticks(ticks)
plt.ylim(0,0.25)
plt.show()
Answered By - Lucas M. Uriarte
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.