New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Aligning axvline
and axhline
with increasing linewidth
#3731
Comments
Okay I found out what the issue was. Using an IPython Notebook I had a graph like this #!/usr/bin/python3
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
np.random.seed(42)
plt.rcParams.update({'font.size': 23, 'font.family': 'serif'})
f, ax = plt.subplots(1, 1, figsize=(16,10), dpi=600)
data = np.random.rand(50)
hist, bins = np.histogram(data, bins=99, range=(0.0, 1.0))
midpoints, hist = [0.5, 0.25]
ax.bar(midpoints, hist, align='center', width=0.9*(bins[1]-bins[0]),
color='green')
ax.axis([0, 1, 0, 0.35])
ax.grid(True)
ax.axvline(x=0.5, linewidth=2, alpha=0.5) The vertical line is not centered on my screen - because the bar and vertical line width are displayed using 7 and 2 pixels respectively. I then increased the scale of the graphic in my IPython Notebook using the bottom right edge, but the graphic did not rerender (why?) and hence the imbalance remained even after rescaling. In that sense if we increase the linewidth from 1 to 2 pixels, we get an imbalance. I cannot reproduce the originally reported issue of 'expanding only to the right'. In sum, this is probably not an issue with matplotlib, but just a property that comes from using pixels to display stuff. |
There is also a |
Yes, |
I would like to draw a vertical line at
x=0.5
, and I want it to be visible, so I useHowever, it seems that the line gets fatter asymmetrically, expanding only to the right. If I set
linewidth=20
this becomes even more visible.How can I align the line to remain centered around
x=0.5
, even with increasing width?Is there an argument in
axvline
/axhline
equivalent toax.bar
'salign='center'
?The text was updated successfully, but these errors were encountered: