Questions tagged [matplotlib]

Matplotlib is a 2D plotting library for Python, built on NumPy and often used interactively with IPython. Its "pylab" interface is similar to the plotting functions of MATLAB®.

Filter by
Sorted by
Tagged with
0 votes
1 answer
44 views

Matplotlib and Latex with all bold

I used to render all my Matplotlib fonts with latex and bold as follows: plt.rc('font', family='serif',size=20) matplotlib.rc('text', usetex=True) matplotlib.rc('legend', fontsize=14) matplotlib....
  • 177
1 vote
1 answer
217 views

Formating a scalebar with Latex in the title of a Matplotlib figure

I have an image in matplotlib, and I want to put a scalebar in the title using Latex syntax. Using the \vdash and \dashv commands I can get the ends of the scalebar, as can been seen in the Figure, ...
0 votes
1 answer
32 views

PGF generated with matplotlib contourf produces artifacts in pdf

I generate a contourplot with matplotlib.pyplot.contourf that produces a nice preview image: But when I include the image into my document (using the exact same settings that I successfully employ ...
  • 101
0 votes
0 answers
32 views

Matplotlib PGF Greek Char

To include plots in Latex I use pythons matplotlib (v3.5.2). The plots are then exported as pgf so that they can be included in the latex document (with \input...). However, as soon as I use a Greek ...
  • 15
1 vote
1 answer
411 views

Saving plots with a legend tikzplotlib gives an Error in latex

I'm getting an error when I generate a (line)plot with either matplotlib or Seaborn and save it with tikzplotlib to use it later in latex. Everything works until I add a legend to the plot. This ...
2 votes
0 answers
130 views

Reduce file size of imported graphics and their fonts

I am looking to reduce the file size of the final version of my thesis as much as possible without real hassle and any loss of quality. At the moment it is around 7 MB. I read much about it (...
  • 21
2 votes
1 answer
297 views

Matplotlib PGF backend packages installed by Latex

I want to produce an image to use in Latex. The PDF image is quite large (~200 MB), and as a solution, I wanted to use the PGF backend. So, using the guide here, I added this line: plt.savefig('figure....
  • 125
1 vote
0 answers
184 views

Legend and axis label of pgf plot displayed differently in beamer

I created different plots with matplotlib, which I export as .pgf files. I then import these plots again in latex to display them in my document. This process works fine with the following code: ...
  • 113
9 votes
0 answers
138 views

Using some packages adds a vertical offset when using LaTeX to render text in matplotlib/python figures

I was advised to post here in the comments on a post I made on Stack Overflow. I'm using LaTeX to render my text in figures in the Python package matplotlib. My problem was that when I added siunitx ...
1 vote
0 answers
114 views

Create font package to use custom vectorial symbols via FontForge

This question builds upon my attempt to include custom, vectorial, LaTeX symbols inside Python plots via tikz, which (so far) is failing due to the impossibility (my inability ?) to attach proper font ...
  • 121
1 vote
0 answers
111 views

Creating new symbols with full font-metrics and vector quality

(Note: this question is similar to quite a few others on SO (e.g. this one, that one, that other one, ... but I could find none discussing the explicit need for the new symbols to have proper font ...
  • 121
0 votes
0 answers
149 views

Using PythonTex in Lyx on a Mac

I would like to use PythonTex in Lyx on a Mac. I don't understand the intricacy of Lyx/Tex etc. I think I managed to install PythonLex by installing MacTex 2021 which also installed Tex Live Utility ...
0 votes
2 answers
641 views

matplotlib pgf backend with lualatex - non-math font does not change

When using Python's matplotlib to produce plots, I sometimes require the lualatex engine using the pgf backend for matplotlib when producing "heavier" plots like hexbin, otherwise the TeX ...
0 votes
0 answers
70 views

Are there any potential risks of avoiding type 3 fonts when using matplotlib to draw figures

Many conferences/journals start asking me to use Type 1 font in the submitted PDF. So when I use matplotlib to generate figures, I have two choices: Configure matplotlib to only use tex fonts ...
  • 133
3 votes
1 answer
758 views

twinx x-ticklabels not showing properly when input to latex document

I have a plot with two datasets, using the same x-axis data, so I want to plot this using the twinx functionality in python's matplotlib. To typeset the resulting graph in my latex document that the ...
  • 33
1 vote
3 answers
1k views

Matplotlib, Inkscape, TeXStudio workflow SVG figures

When I create an SVG figure in matplotlib import numpy as np import matplotlib.pyplot as plt import matplotlib new_rc_params = {'text.usetex': False, "svg.fonttype": 'none' } matplotlib....
1 vote
0 answers
336 views

Error in Matplotlib in legend

If I include this plt.legend(['$0.25+\zeta$'], loc = 1)in my code, I am not getting error. But plt.legend(['$\frac{1}{4}+\frac{\alpha}{10}$'], loc = 1) gives error.
  • 3,211
2 votes
1 answer
941 views

Writing probability density function in Latex

How to write the following probability density function for gaussian distribution in Latex (Matplotlib) p(x) = \frac{1}{\sqrt{ 2 \pi \sigma^2 }} e^{ - \frac{ (x - \mu)^2 } {2 \sigma^2} },
0 votes
0 answers
2k views

Matplotlib : Why doesn't legend font appear as Latex rendering

Below the PDF output generated by a Python script : As you can see, labels and title are correctly appearing as Latex rendering. Excepted the fact that Latex font is not applied for legend and I don'...
0 votes
0 answers
72 views

Issue about mixing font labels text and maths equations with \bm option

I try to generate a pdf from this source in python (matplotlib), in order to have a Latex style : mpl.use("pgf") rc_fonts = { "text.usetex": True, 'text.latex.preview': ...
1 vote
0 answers
92 views

pdflatex hangs when compiling some pdf files [closed]

I'm using TeXstudio an a Mac and have found that some pgf files (obtained from python's Matplotlib), cause the compilation to hang. Also, when I run pdflatex from the terminal, it hangs on: [13] (./...
  • 193
0 votes
0 answers
1k views

Latex does not work in Python's matplotlib

I installed MikTex and try to plot some graphs using Matplotlib. There, I want to use Latex, but I get the following error: File "C:\Users\Leo\anaconda3\lib\site-packages\matplotlib\texmanager....
1 vote
0 answers
118 views

Externalize PGF file that includes a cross-reference

I have some figures as PGF files that include cross-references in them. Each time I compile my main document, these figures are recompiled too. Therefore I would like to externalize these figures. The ...
  • 11
3 votes
2 answers
3k views

What is the best way to include matplotlib plots?

I work on both Windows and Linux. I already include SVG graphics that I create in Inkscape with \usepackage{svg}. For maintainablitly reasons I would welcome to re-use that for matplotlib plots, but I ...
1 vote
1 answer
312 views

Include “contour” package into matlplotlib and set title using it

I transfer the initial post from stackoverflow since one said it is rather a question for Tex exchange (I am going do delete the initial one). Here is this post : In a matplotlib script, I try to ...
0 votes
0 answers
915 views

Formatting Matplotlib figure with subplots for Latex

I'm having trouble getting my plot to span the entire \textwidth. Here is an equivalent MWE of what I'm getting when I compile. Matplotlib code: (set_size is a function taken from here, but that doesn'...
1 vote
1 answer
4k views

How to get Latex bold greek symbol with matplotlib for a title above a subplot [closed]

I have the following subplot (indexed by mand ngiven) : ax = g.subplots[m,n] I tried to set in bold Latex all the Latex expression $1 sigma \pm 0.1$. I have set up at the beginning of matplotlib ...
0 votes
1 answer
139 views

Less xticks in pgfplots loglog

I use tikzplotlib to produce pfgplots figures from matplotlib. Here's the output I get trying to produces a loglog plot: Obviously there is something wrong with the x axis ticks. I would like to have ...
user avatar
0 votes
1 answer
426 views

Matplotlib PGF Export: Error Dimension too large

I have an issue I could not find any other threads on, only for people who create their pgf plot manually. I have created a boxplot using matplotlib and Seaborn. I want to export this plot to TeX, so ...
  • 101
2 votes
1 answer
1k views

using plot with legend saved with tikzplotlib gives Error in latex

I am generating a plot with matplotlib and save it with tikzplotlib to use it later in latex. It works fine till the point where I use a legend in the plot. Then latex gives me the following Error ...
0 votes
1 answer
86 views

Including .pgf plots with sans serif fonts in a serif document

I am creating the plots and figures for my thesis using matplotlib and save them as .pgf files that I include using \begin{figure} \input{myfigure.pgf} \caption{A caption} \end{figure} ...
4 votes
2 answers
9k views

Can't save image as eps in matplotlib when using tex since new install

I want to save a plot from matplotlib as an eps file, which has worked previously with no problem. However, today I reinstalled latex and ever since, I have trouble with eps. I have the following MWE ...
0 votes
1 answer
178 views

How to refer to non-existing subfigure?

I ploted a big figure with several subfigures in it using matplotlib, because the library provides many features that are difficult to implement in tex (like shared label and shared axis). However, I ...
  • 101
0 votes
0 answers
89 views

Crop a pgf image to extents

I'm generating a fair bit of plots with matplotlib for my document. For consistent white space between plots, images, etc. I'd like to crop the plot images which are pgf to the extents of the plot "...
2 votes
0 answers
1k views

PGF generated plot via Matplotlib and using relative font sizes when input to LaTeX

I can produce plots on matplotlib and export them to pgf successfully. But I believe that by first defining a base font size on matplotlib rcParams (11pt for example), and then defining things like ...
0 votes
0 answers
542 views

How to force sans-serif fonts in matplotlib with xelatex PGF backend

This is a slightly borderline question for matplotlib-xelatex combination. I ma having an issue forcing a sans-serif font family in a png/pdf output of my matplotlib. I wanted to use tex rendering ...
1 vote
0 answers
3k views

Including python matplotlib plots in LaTeX documents and inheriting document font properties

I am trying to get a standardised method to import plots from matplotlib into my LaTeX document, borrowing text formatting from the main document (so I want to avoid pure PDF). I am currently ...
  • 11
2 votes
1 answer
661 views

Scale down the size of a PGF figure

I've created a plot using matplotlib in Python and saved it to a PGF which I've then embedded in my LaTeX document. I'd like it to be a bit smaller, as is it won't centre and it forces down a section'...
2 votes
2 answers
10k views

Matplotlib error: No such file or directory: 'latex': 'latex'

I am running a public code downloaded from GitHub, but I have a problem when it gets to the end and it has to plot the results using LaTeX. I get the following error: FileNotFoundError: [Errno 2] ...
1 vote
1 answer
667 views

Reference in latex document to part of Matplotlib (pgf) generated figure

I have a Python script which draws a plot similar to this: fig = plt.figure() ax = plt.axes() x = np.linspace(-2,2,10) y = x**2 ax.plot(x, y, label='$x^2$', color="#07529a", linewidth=2.0) # <--...
1 vote
0 answers
1k views

How to include figures using Pythontex

I try the solution of G.Poore (https://github.com/gpoore/pythontex/wiki/matplotlib) in order to include easily a lot of figures in a TeX document using Pythontex. Unfortunately I get the following ...
  • 783
2 votes
1 answer
2k views

The one of the Matploltlib example

import numpy as np import matplotlib matplotlib.rcParams['text.usetex'] = True import matplotlib.pyplot as plt t = np.linspace(0.0, 1.0, 100) s = np.cos(4 * np.pi * t) + 2 fig, ax = plt.subplots(...
  • 21
4 votes
2 answers
390 views

How can I put a ring accent below (or inside) a letter in math mode?

I need to put a circle (ring, zero etc.) below or inside a \Lambda letter. I need to do so both in math mode of LaTeX document and in mathtext mode of matplotlib - so my choice of commands is limited....
  • 207
2 votes
0 answers
369 views

LaTeX matplotlib pgf shows no colorbar - instead shows colorbar png image filename [duplicate]

Moved from Stack Overflow I'm producing various plots with matplotlib and save them as PGF files. These are then imported in my LaTeX file and compiled using the pgf package. The problem is, I can't ...
0 votes
1 answer
2k views

Including a complex Matplotlib.Pytplot figure in Latex [duplicate]

I'm not sure if I should post this on the Python SE or here. I have made a complex figure in Python that is exactly how I want it to be. Now I want to include that figure in my thesis in LaTeX. As of ...
  • 481
1 vote
1 answer
2k views

I do not know the key /tikz/none

I used matplotlib2tikz and now get the Package pgfkeys error: I do not know the key /tikz/none when I compile. I have \RequirePackage{pgfplots} and \RequirePackage[utf8]{inputenc} specified but it ...
  • 125
2 votes
0 answers
925 views

Matplotlib PDF figures blurry when printed

I'm creating my figures with Matplotlib. They are in the standard pdf output format of Matplotlib and I include them with \includegraphics{figure.pdf}. In my python scripts I activated the usetex flag ...
2 votes
1 answer
11k views

Matplotlib2tikz Increase spacing between ticks

I am using matplotlib2tikz to plot a barchart. However, the ticks are not spaced out enough. How do I increase the spacing between the results? My code: import matplotlib matplotlib.use("Agg") ...
  • 21
0 votes
1 answer
737 views

Missing { inserted within matplotlib2tikz figure

After using matplotlib to create a bar chart, I use matplotlib2tikz to create a tikz figure. The code is as following: % This file was created by matplotlib2tikz v0.6.13. \begin{tikzpicture} \...
7 votes
1 answer
8k views

How to use the \siunitx package within Python/matplotlib?

I'm writing a LaTeX document and I include some matplotlib plots in it, in .pgf format with \include{file.pgf}. It has advantages over exporting the matplotlib plot to .pdf or .eps formats in that the ...