Relative Content

Tag Archive for python-3.xmatplotlib

Place text at same y-position as xlabel

import matplotlib.pyplot as plt fig, ax = plt.subplots(figsize=(10, 10), tight_layout=True) ax.plot([-0.5, 0.6], [1, 1.35]) xlabel = ax.set_xlabel(“TEST”) y = xlabel.get_window_extent().transformed(ax.transAxes.inverted()).y0 ax.text(s=’TEST_position’, x=0.25, y=y, transform=ax.transAxes) The text ‘TEST_position’ should be placed at the same y-position of the xlabel. My approach does not work. python-3.x matplotlib

negative value is set on wrong location

import pandas as pd import matplotlib.pyplot as plt df = pd.DataFrame({‘X’: [474, -362, -575, -575, -108, 474, 474], ‘Y’: [380, 350, 350, 420, 440, 440, 380]}) fig, ax = plt.subplots() ax.plot(UQ[‘X’], UQ[‘Y’]) Why is the value of -108 on the right instead of between -362 and 474? python-3.x matplotlib