Python matplotlib decrease size of colorbar labels












45















I need your help! I have a plotting code which is the following:



fig = plt.figure()
ax1 = fig.add_subplot(111)

imax1 = ax1.imshow(data,interpolation = 'nearest', origin = 'lower',cmap=cm.jet)#plot
cbar = plt.colorbar(imax1, extend='neither', spacing='proportional',
orientation='vertical', shrink=0.7, format="%.0f")
cbar.set_label(r"ET [mm/month]", size=10)

titlestr = "Evapotranspiration in mm/month"
plt.title(titlestr)
#plt.xlabel("Longitude")
#plt.ylabel("Latitude")
imax1.set_clim(0,60)
labels = [item.get_text() for item in ax1.get_xticklabels()]
for ii in range(np.shape(labels)[0]):
labels[ii] = str(grid_lon[75*ii/np.shape(labels)[0]])

ax1.set_xticklabels(labels, rotation = 45, ha='right', size = 10)

labels = [item.get_text() for item in ax1.get_yticklabels()]
for ii in range(np.shape(labels)[0]):
labels[ii] = str(grid_lat[75*ii/np.shape(labels)[0]])

ax1.set_yticklabels(labels, size = 10)

pngname = "./out/2d_"+variable+"_"+mm+".png"
print "save ", pngname
plt.savefig(pngname, dpi=None, facecolor='w', edgecolor='w',
orientation='portrait', papertype=None, format=None,
transparent=False, bbox_inches=None, pad_inches=0.1)


print "plot finished"


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 go into the line "imax1.set_clim(0,60). Any ideas? I'd be also interested to print information of the imax1 object to command line. How could I do that? E.g. available attributes and functions of imax1.



I deeply appreciate your help!










share|improve this question























  • Partial answer: print dir(imax1) will give you information regarding available attributes and functions of imax1.

    – crayzeewulf
    Mar 9 '13 at 0:55











  • great thanks, I implemented the lower one.

    – user1113953
    Mar 9 '13 at 9:05
















45















I need your help! I have a plotting code which is the following:



fig = plt.figure()
ax1 = fig.add_subplot(111)

imax1 = ax1.imshow(data,interpolation = 'nearest', origin = 'lower',cmap=cm.jet)#plot
cbar = plt.colorbar(imax1, extend='neither', spacing='proportional',
orientation='vertical', shrink=0.7, format="%.0f")
cbar.set_label(r"ET [mm/month]", size=10)

titlestr = "Evapotranspiration in mm/month"
plt.title(titlestr)
#plt.xlabel("Longitude")
#plt.ylabel("Latitude")
imax1.set_clim(0,60)
labels = [item.get_text() for item in ax1.get_xticklabels()]
for ii in range(np.shape(labels)[0]):
labels[ii] = str(grid_lon[75*ii/np.shape(labels)[0]])

ax1.set_xticklabels(labels, rotation = 45, ha='right', size = 10)

labels = [item.get_text() for item in ax1.get_yticklabels()]
for ii in range(np.shape(labels)[0]):
labels[ii] = str(grid_lat[75*ii/np.shape(labels)[0]])

ax1.set_yticklabels(labels, size = 10)

pngname = "./out/2d_"+variable+"_"+mm+".png"
print "save ", pngname
plt.savefig(pngname, dpi=None, facecolor='w', edgecolor='w',
orientation='portrait', papertype=None, format=None,
transparent=False, bbox_inches=None, pad_inches=0.1)


print "plot finished"


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 go into the line "imax1.set_clim(0,60). Any ideas? I'd be also interested to print information of the imax1 object to command line. How could I do that? E.g. available attributes and functions of imax1.



I deeply appreciate your help!










share|improve this question























  • Partial answer: print dir(imax1) will give you information regarding available attributes and functions of imax1.

    – crayzeewulf
    Mar 9 '13 at 0:55











  • great thanks, I implemented the lower one.

    – user1113953
    Mar 9 '13 at 9:05














45












45








45


9






I need your help! I have a plotting code which is the following:



fig = plt.figure()
ax1 = fig.add_subplot(111)

imax1 = ax1.imshow(data,interpolation = 'nearest', origin = 'lower',cmap=cm.jet)#plot
cbar = plt.colorbar(imax1, extend='neither', spacing='proportional',
orientation='vertical', shrink=0.7, format="%.0f")
cbar.set_label(r"ET [mm/month]", size=10)

titlestr = "Evapotranspiration in mm/month"
plt.title(titlestr)
#plt.xlabel("Longitude")
#plt.ylabel("Latitude")
imax1.set_clim(0,60)
labels = [item.get_text() for item in ax1.get_xticklabels()]
for ii in range(np.shape(labels)[0]):
labels[ii] = str(grid_lon[75*ii/np.shape(labels)[0]])

ax1.set_xticklabels(labels, rotation = 45, ha='right', size = 10)

labels = [item.get_text() for item in ax1.get_yticklabels()]
for ii in range(np.shape(labels)[0]):
labels[ii] = str(grid_lat[75*ii/np.shape(labels)[0]])

ax1.set_yticklabels(labels, size = 10)

pngname = "./out/2d_"+variable+"_"+mm+".png"
print "save ", pngname
plt.savefig(pngname, dpi=None, facecolor='w', edgecolor='w',
orientation='portrait', papertype=None, format=None,
transparent=False, bbox_inches=None, pad_inches=0.1)


print "plot finished"


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 go into the line "imax1.set_clim(0,60). Any ideas? I'd be also interested to print information of the imax1 object to command line. How could I do that? E.g. available attributes and functions of imax1.



I deeply appreciate your help!










share|improve this question














I need your help! I have a plotting code which is the following:



fig = plt.figure()
ax1 = fig.add_subplot(111)

imax1 = ax1.imshow(data,interpolation = 'nearest', origin = 'lower',cmap=cm.jet)#plot
cbar = plt.colorbar(imax1, extend='neither', spacing='proportional',
orientation='vertical', shrink=0.7, format="%.0f")
cbar.set_label(r"ET [mm/month]", size=10)

titlestr = "Evapotranspiration in mm/month"
plt.title(titlestr)
#plt.xlabel("Longitude")
#plt.ylabel("Latitude")
imax1.set_clim(0,60)
labels = [item.get_text() for item in ax1.get_xticklabels()]
for ii in range(np.shape(labels)[0]):
labels[ii] = str(grid_lon[75*ii/np.shape(labels)[0]])

ax1.set_xticklabels(labels, rotation = 45, ha='right', size = 10)

labels = [item.get_text() for item in ax1.get_yticklabels()]
for ii in range(np.shape(labels)[0]):
labels[ii] = str(grid_lat[75*ii/np.shape(labels)[0]])

ax1.set_yticklabels(labels, size = 10)

pngname = "./out/2d_"+variable+"_"+mm+".png"
print "save ", pngname
plt.savefig(pngname, dpi=None, facecolor='w', edgecolor='w',
orientation='portrait', papertype=None, format=None,
transparent=False, bbox_inches=None, pad_inches=0.1)


print "plot finished"


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 go into the line "imax1.set_clim(0,60). Any ideas? I'd be also interested to print information of the imax1 object to command line. How could I do that? E.g. available attributes and functions of imax1.



I deeply appreciate your help!







python attributes matplotlib labels colorbar






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 9 '13 at 0:36









user1113953user1113953

2641410




2641410













  • Partial answer: print dir(imax1) will give you information regarding available attributes and functions of imax1.

    – crayzeewulf
    Mar 9 '13 at 0:55











  • great thanks, I implemented the lower one.

    – user1113953
    Mar 9 '13 at 9:05



















  • Partial answer: print dir(imax1) will give you information regarding available attributes and functions of imax1.

    – crayzeewulf
    Mar 9 '13 at 0:55











  • great thanks, I implemented the lower one.

    – user1113953
    Mar 9 '13 at 9:05

















Partial answer: print dir(imax1) will give you information regarding available attributes and functions of imax1.

– crayzeewulf
Mar 9 '13 at 0:55





Partial answer: print dir(imax1) will give you information regarding available attributes and functions of imax1.

– crayzeewulf
Mar 9 '13 at 0:55













great thanks, I implemented the lower one.

– user1113953
Mar 9 '13 at 9:05





great thanks, I implemented the lower one.

– user1113953
Mar 9 '13 at 9:05












1 Answer
1






active

oldest

votes


















141














Aha! Found the answer here:



cbar.ax.tick_params(labelsize=10) 


P.S. Upvote that answer and give Paul some love!






share|improve this answer


























  • Note: cbar.ax.tick_params(labelsize='xx-small') also works

    – user66081
    Dec 18 '18 at 11:35











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f15305737%2fpython-matplotlib-decrease-size-of-colorbar-labels%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









141














Aha! Found the answer here:



cbar.ax.tick_params(labelsize=10) 


P.S. Upvote that answer and give Paul some love!






share|improve this answer


























  • Note: cbar.ax.tick_params(labelsize='xx-small') also works

    – user66081
    Dec 18 '18 at 11:35
















141














Aha! Found the answer here:



cbar.ax.tick_params(labelsize=10) 


P.S. Upvote that answer and give Paul some love!






share|improve this answer


























  • Note: cbar.ax.tick_params(labelsize='xx-small') also works

    – user66081
    Dec 18 '18 at 11:35














141












141








141







Aha! Found the answer here:



cbar.ax.tick_params(labelsize=10) 


P.S. Upvote that answer and give Paul some love!






share|improve this answer















Aha! Found the answer here:



cbar.ax.tick_params(labelsize=10) 


P.S. Upvote that answer and give Paul some love!







share|improve this answer














share|improve this answer



share|improve this answer








edited May 23 '17 at 12:02









Community

11




11










answered Mar 9 '13 at 1:06









crayzeewulfcrayzeewulf

4,25512027




4,25512027













  • Note: cbar.ax.tick_params(labelsize='xx-small') also works

    – user66081
    Dec 18 '18 at 11:35



















  • Note: cbar.ax.tick_params(labelsize='xx-small') also works

    – user66081
    Dec 18 '18 at 11:35

















Note: cbar.ax.tick_params(labelsize='xx-small') also works

– user66081
Dec 18 '18 at 11:35





Note: cbar.ax.tick_params(labelsize='xx-small') also works

– user66081
Dec 18 '18 at 11:35


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f15305737%2fpython-matplotlib-decrease-size-of-colorbar-labels%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Hercules Kyvelos

Tangent Lines Diagram Along Smooth Curve

Yusuf al-Mu'taman ibn Hud