question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Change the label size and tick label size of colorbar

See original GitHub issue

MCVE Code Sample

# Your code here
import xarray as xr

airtemps = xr.tutorial.open_dataset('air_temperature')
air = airtemps.air - 273.15
air2d = air.isel(time=500)
air2d.plot.pcolormesh(add_colorbar=True, add_labels=True,
                      cbar_kwargs=dict(orientation='horizontal',
                      pad=0.15, shrink=1, label='Temperature ($^{\circ}$C)'))

Expected Output

image

Problem Description

Is it possible to change the label size and ticks label size of colorbar? size and labelsize don’t work in cbar_kwargs.

Output of xr.show_versions()

# Paste the output here xr.show_versions() here INSTALLED VERSIONS ------------------ commit: None python: 3.6.7 (default, Feb 28 2019, 07:28:18) [MSC v.1900 64 bit (AMD64)] python-bits: 64 OS: Windows OS-release: 10 machine: AMD64 processor: Intel64 Family 6 Model 158 Stepping 9, GenuineIntel byteorder: little LC_ALL: None LANG: None LOCALE: None.None libhdf5: 1.10.4 libnetcdf: 4.6.2

xarray: 0.12.1 pandas: 0.24.2 numpy: 1.16.3 scipy: 1.2.1 netCDF4: 1.5.1.1 pydap: None h5netcdf: None h5py: 2.9.0 Nio: None zarr: None cftime: 1.0.3.4 nc_time_axis: None PseudonetCDF: None rasterio: 1.0.22 cfgrib: None iris: None bottleneck: None dask: 1.2.0 distributed: 1.27.1 matplotlib: 3.1.1 cartopy: 0.17.0 seaborn: None setuptools: 41.0.1 pip: 19.1 conda: None pytest: None IPython: 7.6.1 sphinx: None

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
zxdawncommented, Sep 2, 2019

@dcherian Thanks! Figure out now:

import xarray as xr
import matplotlib.pyplot as plt

airtemps = xr.tutorial.open_dataset('air_temperature')
air = airtemps.air - 273.15
air2d = air.isel(time=500)

im = air2d.plot.pcolormesh(add_colorbar=False)
cb = plt.colorbar(im, orientation="horizontal", pad=0.15)
cb.set_label(label='Temperature ($^{\circ}$C)', size='large', weight='bold')
cb.ax.tick_params(labelsize='large')

image

1reaction
aaraneycommented, Jun 15, 2021

@Ricbrag something like this should work:

import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt

a=np.random.rand(10,10)
im=plt.imshow(a)
cb=plt.colorbar(im,orientation='horizontal').set_label(label='Label',size=20,weight='bold')

im.figure.axes[0].tick_params(axis="both", labelsize=5)
im.figure.axes[1].tick_params(axis="x", labelsize=20)

plt.show()

image

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I change the font size of ticks of matplotlib.pyplot ...
Initialize a variable for fontsize to change the tick size of the colorbar. Use axis tick_params() method to set the tick size of...
Read more >
Change the label size and tick label size of colorbar using ...
In this article, we will learn how to change the label size and tick label size of colorbar in Matplotlib using Python. Labels...
Read more >
Python matplotlib decrease size of colorbar labels
I would like to set the label size of the colorbar labels (e.g. 0,10,20,...60) to size of 10 or smaller. This will probably...
Read more >
Colorbar appearance and behavior - MATLAB - MathWorks
ColorBar properties control the appearance and behavior of a ColorBar object. ... TickLabelInterpreter — Tick label interpreter ... FontSize — Font size
Read more >
How to modify label size in colorbar of seaborn clustermap?
position and I changed the yticks label with this command plt.tick_params(labelsize=15), but I'm not able to change the size of the label? Is ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found