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
24
votes
4 answers

How to plot stacked event duration (Gantt Charts)

I have a Pandas DataFrame containing the date that a stream gage started measuring flow and the date that the station was decommissioned. I want to generate a plot showing these dates graphically. Here is a sample of my DataFrame: import pandas as…
Inkenbrandt
  • 336
  • 2
  • 3
  • 12
24
votes
1 answer

Add custom border to certain cells in a matplotlib / seaborn plot

Right now I`m using Seaborn's clustermap to generate some clustered heatmaps - so far so good. For a certain use case, I need to draw colored borders around specific cells. Is there a way to do that? Or with pcolormesh in matplotlib, or any other…
Justin Nelligan
  • 455
  • 1
  • 6
  • 12
24
votes
1 answer

Combining two matplotlib colormaps

I would like to merge two colormaps into one, such that I can use one cmap for negative values and the other one for positive values. At the moment I do it with masked arrays and plotting one image with one cmap and the other image with the other,…
johnbaltis
  • 1,413
  • 4
  • 14
  • 26
24
votes
5 answers

matplotlib make axis ticks label for dates bold

I want to have bold labels on my axis, so I can use the plot for publication. I also need to have the label of the lines in the legend plotted in bold. So far I can set the axis labels and the legend to the size and weight I want. I can also set the…
red_tiger
  • 1,402
  • 3
  • 16
  • 32
24
votes
3 answers

Scatterplot without linear fit in seaborn

I am wondering if there is a way to turn off the linear fit in seaborn's lmplot or if there is an equivalent function that just produces the scatterplot. Sure, I could also use matplotlib, however, I find the syntax and aesthetics in seaborn quite…
user2489252
24
votes
5 answers

How to create ternary contour plot in Python?

I have a data set as follows (in Python): import numpy as np A = np.array([0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 0, 0.1, 0.2, 0.3, 0.4, 0.2, 0.2, 0.05, 0.1]) B = np.array([0.9, 0.7, 0.5, 0.3, 0.1, 0.2, 0.1, 0.15, 0, 0.1, 0.2, 0.3, 0.4, 0.5,…
Tom Kurushingal
  • 6,086
  • 20
  • 54
  • 86
24
votes
2 answers

Frequency plot in Python/Pandas DataFrame

I have a parsed very large dataframe with some values like this and several columns: Name Age Points ... XYZ 42 32pts ... ABC 41 32pts ... DEF 32 35pts GHI 52 35pts JHK 72 35pts MNU 43 42pts LKT 32 32pts LKI 42 42pts JHI 42 …
SMU
  • 241
  • 1
  • 2
  • 3
24
votes
7 answers

Find the area between two curves plotted in matplotlib (fill_between area)

I have a list of x and y values for two curves, both having weird shapes, and I don't have a function for any of them. I need to do two things: Plot it and shade the area between the curves like the image below. Find the total area of this shaded…
F4R
  • 403
  • 1
  • 3
  • 11
24
votes
3 answers

Sans-serif math with latex in matplotlib

The following script: import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as mpl mpl.rc('font', family='sans-serif') mpl.rc('text', usetex=True) fig = mpl.figure() ax = fig.add_subplot(1,1,1) ax.text(0.2,0.5,r"Math font:…
astrofrog
  • 32,883
  • 32
  • 90
  • 131
24
votes
2 answers

Matplotlib: Move ticklabels between ticks

I want to create a visualization of a confusion matrix using matplotlib. Parameters to the methods shown below are the class labels (alphabet), the classification results as a list of lists (conf_arr) and an output filename. I am pretty happy with…
feob
  • 1,930
  • 5
  • 19
  • 31
24
votes
3 answers

Move and resize legends-box in matplotlib

I'm creating plots using Matplotlib that I save as SVG, export to .pdf + .pdf_tex using Inkscape, and include the .pdf_tex-file in a LaTeX document. This means that I can input LaTeX-commands in titles, legends etc., giving an image like…
Filip S.
  • 1,514
  • 3
  • 19
  • 40
24
votes
4 answers

Python : How to plot 3d graphs using Python?

I am using matplotlib for doing this from mpl_toolkits.mplot3d import Axes3D import numpy as np import matplotlib import matplotlib.pyplot as plt fig = plt.figure() ax = Axes3D(fig) x = [6,3,6,9,12,24] y = [3,5,78,12,23,56] ax.plot(x, y, zs=0,…
Bruce
  • 33,927
  • 76
  • 174
  • 262
24
votes
3 answers

Changing matplotlib subplot size/position after axes creation

Is it possible to set the size/position of a matplotlib subplot after the axes are created? I know that I can do: import matplotlib.pyplot as plt ax = plt.subplot(111) ax.change_geometry(3,1,1) to put the axes on the top row of three. But I want…
RuthC
  • 1,269
  • 1
  • 10
  • 21
24
votes
2 answers

Turn off axis border for polar matplotlib plot

I have a polar axes in matplotlib that has text which extends outside of the range of the axes. I would like to remove the border for the axis -- or set it to the color of the background so that the text is more legible. How can I do this? Simply…
aestrivex
  • 5,170
  • 2
  • 27
  • 44
24
votes
1 answer

Plotting histograms against classes in pandas / matplotlib

Is there a idiomatic way to plot the histogram of a feature for two classes? In pandas, I basically want df.feature[df.class == 0].hist() df.feature[df.class == 1].hist() To be in the same plot. I could do df.feature.hist(by=df.class) but that…
Andreas Mueller
  • 27,470
  • 8
  • 62
  • 74