Strange error with matplotlib axes labels

matplotlib axis label
matplotlib axis label plt
matlab plot axis label python
pyplot axes label font size
matplotlib show all tick labels
labels in matplotlib
matplotlib change font size of axis labels
matplotlib axes not showing

I'm very new to Python and programming in general, so apologies in advance if I'm missing something obvious. I'm trying to plot a graph and label the axes, but every time I try to label the y axis an exception is raised. I wrote the code below in a new script to make sure the problem wasn't coming from somewhere else in the module. I'm using Python 3.4.

from numpy import *
from matplotlib import *

a = [1, 2, 3, 4, 5]
b = [2, 3, 2, 3, 2]
pyplot.plot(a, b)

Every time, I get the error 'TypeError: 'str' object is not callable' for the final line. If I change the y to an x, everything is fine. If I change the x to a y, I get the same error. However, ylabel comes up on the drop down list for ylabel so the function does exist and the documentation says a string is the only necessary argument, exactly as for xlabel (matplotlib.pyplot.ylabel(s, *args, **kwargs) and matplotlib.pyplot.xlabel(s, *args, **kwargs)). What on earth could be going on here?

I had this same issue when working in iPython notebook.

I think it can be re-created as follows:

import matplotlib.pyplot as plt
plt.ylabel = 'somestring' # oh wait this isn't the right syntax.
plt.ylabel('somestring') # now this breaks because the function has been turned into a string

Re-starting the kernel or re-importing the libraries restores plt.ylabel to a function.

Strange error with matplotlib axes labels, I'm very new to Python and programming in general, so apologies in advance if I'​m missing something obvious. I'm trying to plot a graph and label the axes, but  Can this be done with matplotlib import matplotlib.pyplot as pltplt.figure()ax1 = plt.errorbar(voltage, dP, xerr=voltageU, yerr=dPU)ax2 = plt.errorbar(voltage, current, xerr=voltageU like this from matplotlib.pyplot import subplots, show

EDIT: This code works fine for clean runs, but you might have changed ylabel, in which case restarting should fix it, as @wolfins answered (check that answer).

I'm afraid I can't tell you what's going wrong because it works fine here. The below code runs without error and shows the plot with correct label.

from matplotlib import pyplot, pylab
a = [1, 2, 3, 4, 5]
b = [2, 3, 2, 3, 2]
pyplot.plot(a, b)

If that doesn't work for you, perhaps you can try using figure and axes objects, like this

from matplotlib.pyplot import subplots, show
a = [1, 2, 3, 4, 5]
b = [2, 3, 2, 3, 2]
fig, ax = subplots()
ax.plot(a, b)

Doesn't solve the underlying problem (which is hard since I can't reproduce it), but maybe it will achieve your purpose at least.

Text in Matplotlib Plots, Strange error with matplotlib axes labels - I'm very new to Python and programming in general, so apologies in advance if I'm missing something obvious. I'm trying to use mplot3d in a Wx based application, and most things seem to be working fine. The one issue that keeps tripping me up is that the axes labels are drawn at a weird angle.

I just had this happen to me. It seems that what I did was assign a string to xlab and ylab like:

plt.xlab = 'string'
plt.ylab = 'string'

This broke the xlab and ylab such that you cannot call them anymore, since they are now in fact strings, not functions.

Similarly, I was using Jupyter, and I had to kill Jupyter and re-run it from scratch to fix this problem.

Oddly, re-importing the libraries while the kernal remained running did NOT work.

matplotlib.axes.Axes.legend, I'm very new to Python and programming in general, so apologies in advance if I'​m missing something obvious. I'm trying to plot a graph and label the axes, but  I am creating a figure with 6 filled contour plots and a color bar (so, 7 axes total). The function creating the figure loops over a list of variable pairs and arranges the axes in 3x2 pattern with colorbar at the bottom, with a call to

This usually Happens, if you assign the Xlabel value instead calling . ex: if you want to set the Xlabel to "X-DUMMY". you need to use


but by mistake if you do as below.

plt.xlabel= "X-DUMMY"

you will get this error . Even if you correct it saying .


This issue repeats unless you restart you restart the kernal .

reason being, plt.xlabel is a function. in python functions are first-class objects.once you assigned

 plt.xlabel= "X-DUMMY" 

it get converted to a string. later when ever you try, it throws error as

'TypeError: 'str' object is not callable'.

you can try it by using type(plt.xlabel) before and after assignment. to see its datatype.

(Tutorial) MATPLOTLIB Tutorial: PYTHON Plotting, Basic text commands; Labels for x- and y-axis; Titles; Ticks and ticklabels. Terminology; Simple ticks; Tick Locators and Formatters; Dateticks def formatoddticks(x, pos): """Format odd tick positions """ if x % 2: return '%1.2f' % x else: return  I was having the same problem using Jupyter notebook and the command: %matplotlib notebook. The figure showed correctly in the notebook but didn't print axis and titles when saved with fig.savefig(). I changed %matplotlib notebook to %matplotlib inline and that solved the problem.

I saved the checkpoint and halted the ipython notebook. Then I restarted it which solved the problem.

axes, In this case, the labels are taken from the artist. You can specify them either at artist creation or by calling the set_label() method on the artist: line, = ax.plot([1, 2​,  I fixed the miscalculation of axes label angles, and I made some adjustments to the spacing. For the next release, I would like to have 3d axes to take up more than the default axes spacing, since the default was designed to take into account that tick labels and axes labels would be outside the axes, which is not the case for mplot3d.

Duplicate legend labels with different colors can often result in an , The anatomy of a Matplotlib plot: what is a subplot? There's also the axis labels​, title, and legend to consider when you want to Note that also when you're not working in a Jupyter notebook, you'll still When you're working with this data visualization library for the first time, it might be weird at start  The label text. labelpad scalar, optional, default: None. Spacing in points from the axes bounding box including ticks and tick labels. Other Parameters: **kwargs Text properties. Text properties control the appearance of the label.

pyplot axes labels for subplots object has no attribute 'add_axes' The offending problem seems to be linked to the Strange error with matplotlib axes labels. The Axes class ¶ class matplotlib.axes.Axes (fig, rect, facecolor = None, Get the transformation used for drawing y-axis labels, ticks and gridlines.

Bug report If one makes a scatter plot (or a line graph) having multiple .7/site-​packages/matplotlib/axes/", line 498, in legend **kwargs) File This is kind of strange because the same code works fine for ax.plot . where mfc, mec, ms and mew are aliases for the longer property names, markerfacecolor, markeredgecolor, markersize and markeredgewidth.. Valid kwargs for the marker properties are Lines2D properties:

  • I was unable to reproduce this issue. Your code runs fine for me, with those strings in either the xlabel or ylabel interchangeably.
  • I solved the same issue by opening a fresh terminal and rerunning the code
  • I also think this was the issue too! I make this mistake every now and then. Thanks!
  • Yes, I think this was my error too. Thanks for spotting it!
  • I find the fact that so many people had exactly this error pretty funny :))
  • Very illustrative. It remarks the importance of not falling into this errors. Thank you
  • This should be the correct accepted answer. It was my problem exactly and will probably be everyone's.
  • Thank you, that works. As for my code, after all that, restarting the interpreter has done the trick. Sorry about that!
  • @neptune36 Maybe best change the accepted answer, wolfins seems to have managed to break this in the same way so that's probably more useful
  • Thanks for tagging me. I had no idea this 5 year old question had gotten so much attention!
  • This is completely unrelated to the question.