Questions tagged [matplotlib]

Matplotlib is a plotting library for Python which may be used interactively or embedded in stand-alone GUIs. Its compact "pyplot" interface is similar to the plotting functions of MATLAB®.

Matplotlib is a comprehensive plotting and visualization library for the Python programming language and its NumPy numerical mathematics extension. It provides an object-oriented API for embedding plots into applications using general-purpose GUI toolkits like tkinter, wxPython, Qt, or GTK, Jupyter and IPython notebooks.

There is also a procedural "pyplot" interface based on a state machine (like OpenGL), designed to closely resemble that of MATLAB.

Matplotlib can output PNG, PDF, PS, EPS, TIFF, JPEG, PGF, and SVG files, or plot in windows using a variety of toolkits (including plot animation).

Latest release information on Matplotlib's site.

Resources to get started:

71303 questions
23
votes
2 answers

3D scatter plot with color gradient

How can I create a 3D plot with a color gradient for the points? See the example below, which works for a 2D scatter plot. Edit (thanks to Chris): What I'm expecting to see from the 3D plot is a color gradient of the points ranging from red to green…
andrea.ge
  • 1,937
  • 1
  • 18
  • 27
23
votes
2 answers

Setting the display range suplot of errorbars in matplotlib

I'm trying to plot my data using matplot lib. I have 3 separetes sets of data I want to plot in 3 subplots (I'm using this is my guidence): plt.figure() fig, axs = plt.subplots(nrows=3, ncols = 1, sharex=False) ax1 =…
Yotam
  • 10,295
  • 30
  • 88
  • 128
23
votes
3 answers

Text alignment in a Matplotlib legend

I am trying to right-align the entries in a matplotlib axes legend (by default they are left-aligned), but can't seem to find any way of doing this. The setup I have is below: (I have added data and labels to my_fig axes using the ax.plot()…
jeremiahbuddha
  • 9,701
  • 5
  • 28
  • 34
23
votes
6 answers

matplotlib - module 'sip' has no attribute 'setapi'

I just set up the VS Code with all the Python extensions. Python version is 3.8.3 through Anaconda. The interpreter is venv. When I run this code import matplotlib.pyplot as plt An error shows - Exception has occurred: AttributeError module 'sip'…
Egret
  • 421
  • 1
  • 3
  • 13
23
votes
3 answers

TeX rendering, curly braces, and string formatting syntax in matplotlib

I have the following lines to render TeX annotations in my matplotlib plot: import numpy as np import matplotlib.pyplot as plt from matplotlib import rc rc('text', usetex=True) rc('font', family='serif') voltage = 220 notes = r"\noindent $V_2 =…
Kit
  • 30,365
  • 39
  • 105
  • 149
23
votes
2 answers

Half or quarter polar plots in Matplotlib?

I am trying to make a polar plot that goes 180 degrees instead of 360 in Matplotlib similar to http://www.mathworks.com/matlabcentral/fileexchange/27230-half-polar-coordinates-figure-plot-function-halfpolar in MATLAB. Any ideas?
user394430
  • 2,805
  • 2
  • 28
  • 27
23
votes
4 answers

Avoid plotting missing values on a line plot

I want a line plot to indicate if a piece of data is missing such as: However, the code below fills the missing data, creating a potentially misleading chart: import pandas as pd import seaborn as sns from matplotlib import pyplot as plt # load…
Stefan Smirnov
  • 695
  • 3
  • 6
  • 18
23
votes
3 answers

How to display matplotlib plots in a Jupyter tab widget?

I am having trouble displaying plots inside of Jupyter tab widgets. Consider the following snippet: import matplotlib.pyplot as plt import pandas as pd import ipywidgets as widgets import numpy as np out1 = widgets.Output() out2 =…
Arthur Azevedo De Amorim
  • 23,012
  • 3
  • 33
  • 39
23
votes
3 answers

pandas 0.21.0 Timestamp compatibility issue with matplotlib

I just updated pandas from 0.17.1 to 0.21.0 to take advantage of some new functionalities, and ran into compatibility issue with matplotlib (which I also updated to latest 2.1.0). In particular, the Timestamp object seems to be changed…
Kevin S.
  • 1,190
  • 3
  • 11
  • 22
23
votes
2 answers

is seaborn confidence interval computed correctly?

First, I must admit that my statistics knowledge is rusty at best: even when it was shining new, it's not a discipline I particularly liked, which means I had a hard time making sense of it. Nevertheless, I took a look at how the barplot graphs were…
anarcat
  • 5,605
  • 4
  • 32
  • 38
23
votes
4 answers

Annotate the linear regression equation

I tried fitting an OLS for Boston data set. My graph looks like below. How to annotate the linear regression equation just above the line or somewhere in the graph? How do I print the equation in Python? I am fairly new to this area. Exploring…
Naive_Natural2511
  • 687
  • 2
  • 8
  • 20
23
votes
1 answer

How to hide lines in matplotlib?

I do not want to connect points with lines. I know that for that I can use scatter. But, scatter does not work after plot. So, basically I have to lists of points. The points from the first list I do want to connect with lines while the points from…
Roman
  • 124,451
  • 167
  • 349
  • 456
23
votes
7 answers

ImportError: cannot import name cbook

>>> import matplotlib Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.7/dist-packages/matplotlib/__init__.py", line 123, in from . import cbook ImportError: cannot import name…
Anas Mubarak
  • 289
  • 1
  • 3
  • 9
23
votes
3 answers

Bar Chart with multiple labels

The following code only shows the main category ['one', 'two', 'three', 'four', 'five', 'six'] as the x axis labels. Is there a way show subcategory ['A', 'B', 'C', 'D'] as secondary x axis labels? df = pd.DataFrame(np.random.rand(6, 4), …
Meng
  • 1,148
  • 5
  • 15
  • 23
23
votes
2 answers

Black and white boxplots in Seaborn

I am trying to draw multiple black-and-white boxplots using Python's Seaborn package. By default the plots are using a color palette. I would like to draw them in solid black outline. The best I can come up with is: # figure…
denten
  • 691
  • 1
  • 6
  • 15