简体   繁体   中英

matplotlib.figure.add_subplot.vlines orientation

My question involves the orientation of the vlines.

在此处输入图片说明

In the pic, I have thick vlines on tick marks 2 - 6. my goal is to have these bars plotted directly to the right of each tick.

I need to do this because when I click on my graph with the mouse, any value between 1 and 2 will equate to 1. any value between 2 and 3 will equate to 2.

So when someone goes to click on the bar on tick 2, if they click on the left hand side of the bar it'll equate to the wrong tick.

I hope my question is clear, and I appreciate any help.

It sounds like you don't want vlines , instead you want rectangles.

The thickness of vlines (or any line) is controlled by its stroke weight, which is in points. This doesn't directly correspond to a position in "data" coordinates in the plot.

For example, we could use ax.bar to create rectangles that range over the positions you want:

import numpy as np
import matplotlib.pyplot as plt

# Data similar to yours
green = np.array([2.5, 1, 0.9, 0.7, 0.4])
red = green
blue = np.array([3.8, 2, 1.8, 1.5, 0.6])
x = np.arange(2, 7)

# Plot bars where the left edge will be at each x-value
fig, ax = plt.subplots()

ax.bar(x, green, width=1, color='green')
ax.bar(x, red, width=1, bottom=green, color='red')
ax.bar(x, blue, width=1, bottom=green+red, color='blue')

ax.set(xlim=[0.5, 7.5])
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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM