Is it possible to allow the bar of a bar or barh chart to extend beyond the limits of the chart?
For example, if my data is np.asarray([1,3,70,924,3])
and I want to limit total height to 300, is it possible without modifying the underlying data?
Sure. Just set the y-limits of the plot:
import matplotlib.pyplot as plt
import numpy as np
data = np.array([1,3,70,924,3])
plt.bar(np.arange(data.size), data)
plt.ylim([0, 300])
plt.show()
If you want the bar to extend beyond the top of the plot, specify clip_on=False
:
import matplotlib.pyplot as plt
import numpy as np
data = np.array([1,3,70,924,3])
plt.bar(np.arange(data.size), data, clip_on=False)
plt.ylim([0, 300])
plt.show()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.