Skip to content
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

Plot title using loc keyword doesn't override automated title #2981

Closed
ahuang11 opened this issue May 22, 2019 · 2 comments
Closed

Plot title using loc keyword doesn't override automated title #2981

ahuang11 opened this issue May 22, 2019 · 2 comments

Comments

@ahuang11
Copy link
Contributor

import xarray as xr
import matplotlib.pyplot as plt

ds = xr.tutorial.open_dataset('air_temperature')['air'].isel(time=0)

This works as expected

ax = plt.axes()
ds.plot(x='lon', y='lat', ax=ax)
ax.set_title('new_title')

This doesn't

ax = plt.axes()
ds.plot(x='lon', y='lat', ax=ax)
ax.set_title('new_title', loc='left')

With non-default loc, the old title still shows
image

xarray: 0.12.1 pandas: 0.23.4 numpy: 1.15.1 scipy: 1.1.0 netCDF4: 1.4.0 pydap: None h5netcdf: 0.6.1 h5py: 2.9.0 Nio: None zarr: None cftime: 1.0.0 nc_time_axis: None PseudonetCDF: None rasterio: 1.0.1 cfgrib: None iris: None bottleneck: 1.2.1 dask: 1.1.1 distributed: 1.25.3 matplotlib: 3.1.0 cartopy: 0.17.0 seaborn: 0.8.1 setuptools: 39.1.0 pip: 19.0.1 conda: 4.6.14 pytest: 3.5.1 IPython: 6.4.0 sphinx: 1.7.4
@dcherian
Copy link
Contributor

plot calls set_title by default. Not replacing the existing title is matplotlib's default behaviour. (see below). I would just call ax.set_title('') before setting your final title.

ax = plt.gca()
ax.set_title('a')
ax.set_title('b', loc='left')

image

@ahuang11
Copy link
Contributor Author

Cool; that's good to know that I can set a title on the top left and top right side together. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants