I'm a turtle's beginner and I wrote a little program (file.py) who draws something.
But when I call the file with an import statement from another file (theotherfile.py. Note that it use tkinter), I have this error :
Traceback (most recent call last):
File "C:\Users\jeandubois\Documents\GitHub\myproject\theotherfile.py", line 443, in <module>
import theotherfile
File "C:\Users\jeandubois\Documents\GitHub\myproject\file.py", line 10, in <module>
turtle1 = turtle.Turtle()
File "C:\Users\jeandubois\AppData\Local\Programs\Python\Python39\lib\turtle.py", line 3813, in __init__
Turtle._screen = Screen()
File "C:\Users\jeandubois\AppData\Local\Programs\Python\Python39\lib\turtle.py", line 3663, in Screen
Turtle._screen = _Screen()
File "C:\Users\jeandubois\AppData\Local\Programs\Python\Python39\lib\turtle.py", line 3689, in __init__
self._root.setupcanvas(width, height, canvwidth, canvheight)
File "C:\Users\jeandubois\AppData\Local\Programs\Python\Python39\lib\turtle.py", line 438, in setupcanvas
self._canvas = ScrolledCanvas(self, width, height, cwidth, cheight)
File "C:\Users\jeandubois\AppData\Local\Programs\Python\Python39\lib\turtle.py", line 343, in __init__
self._canvas = TK.Canvas(master, width=width, height=height,
File "C:\Users\jeandubois\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 2685, in __init__
Widget.__init__(self, master, 'canvas', cnf, kw)
File "C:\Users\jeandubois\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 2569, in __init__
self.tk.call(
_tkinter.TclError: bad screen distance "0.5"
My code :
# file.py
import tkinter
root = tkinter.Tk()
[some awesome code]
root.mainloop()
# when closing root:
import theotherfile
# theotherfile.py
import turtle
turtle1 = turtle.Turtle()
turtle2 = turtle.Turtle()
turtle3 = turtle.Turtle()
turtle1.speed(100)
turtle2.speed(100)
turtle3.speed(100)
turtle1.width(5)
turtle2.width(5)
turtle3.width(5)
turtle1.color(choice(colors))
turtle2.color(choice(colors))
turtle3.color(choice(colors))
turtle1.up()
turtle2.up()
turtle3.up()
turtle1.goto(-100, -100)
turtle2.goto(0, -100)
turtle3.goto(-50, -13.4)
turtle1.down()
turtle2.down()
turtle3.down()
a = 100
for loop in range(2):
for loop2 in range(3):
turtle1.forward(a)
turtle1.left(120)
turtle2.forward(a)
turtle2.left(120)
turtle3.forward(a)
turtle3.left(120)
turtle1.color(choice(colors))
turtle2.color(choice(colors))
turtle3.color(choice(colors))
a = 50
turtle1.forward(50)
turtle2.forward(50)
turtle3.forward(50)
for loop in range(5):
turtle1.forward(a)
turtle1.left(120)
turtle2.forward(a)
turtle2.left(120)
turtle3.forward(a)
turtle3.left(120)
turtle1.color(choice(colors))
turtle2.color(choice(colors))
turtle3.color(choice(colors))
turtle1.right(60)
turtle2.right(60)
turtle3.right(60)
turtle1.forward(50)
turtle2.forward(50)
turtle3.forward(50)
turtle1.up()
turtle2.up()
turtle3.up()
turtle1.hideturtle()
turtle2.hideturtle()
turtle3.hideturtle()
turtle.mainloop()
I use Python 3.9.0 .
Can someone help me please ?
Related
I am making my own custom Menubar.My work is in process but i recently came across one confusion.
Here is my code:-
from tkinter import *
from tkinter.ttk import Style,Frame as fp
class menu():
def __init__(self,parent,bg="#ffffcc"):
self.parent = parent
self.bg = bg
#this is a image in base 64 encoded format
borderImageData='''
iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAIAAAAlC+aJAAAABmJLR0QA/wD/
AP+gvaeTAAACZ0lEQVRoge2aPU/TURSHn/MvpbYYKa9qQQnlTSOJRBzoYBDi
YEwcdPFD+PIFHHRxcCXxO7gxmBgXSTcxMYQEE4spoEWIvBcDBfp2HVqlxRhK
TDwtuc947vJ7cnPvGc6R/v5+KhlHO8C/YgW0sQLaWAFtqg4WxKEjJMGQaQyK
txbHpZGqmGzG7GzKyoyZfcfsOCZbeChFjaz+vAw/oq6V1K75HiERJ5v+33H/
xKnC55czF3CfYD1mxkbY+Pb7sECguUtuPQbMh5d8eksmpZL2r7jccvEGV++B
Ma+fsRzNlwOBAID3lNx+gjHm1VNiEweuqSwwWZajxCak85oEQ3wOk0my/4j7
7uD1m7ERNuY1Ux7KeozwC3x+uXI3V3AAXFXSPcjCFAtTmuFKw8xPsviRrsHc
B+MANHVS7WPuvXK0kjGz43hqaOogL3CyASC+oJrqKMQXAWoayQmI2wuY1J5q
qKOQ2gXE4+MYdGIroI0V0MYKaGMFtLEC2lgBbayANlZAGyugjRXQxgpoYwW0
sQLaWAFtrIA2DmCSCQC3RzlL6VR7AZIJ8jewtQaIv0Uz05GoPQuYrVXyAqsz
JBO0D+imKh0JhtjbYmWGvEAmbabDtPTSelk5Wimc6yNwiekw2Qz7j3hylERc
hh9S36YZ7jCkoU2GHpjtdTM5mqv8mtSnkyxFpHtQeoZIJ1n7UnbDelc1vTfl
+n1EePOcH0u5cvGyR11r/hJSeyxFzPZGmSx7SE09p3twe1j7asZGCifCcnDt
UhzaBwgOSHMnZbNuw86mWY7K3Lg5ZN2mAjkWnbiisQLaWAFtKl7gJzIjtMOb
uqQwAAAAAElFTkSuQmCC
'''
self.borderImage = PhotoImage( data=borderImageData,master=self.parent)
self.TP_style=Style()
self.TP_style.element_create("RoundedFrame",
"image", self.borderImage,
border=14, sticky="nsew")
self.TP_style.layout("RoundedFrame",
[("RoundedFrame", {"sticky": "nsew"})])
self.frame_one = fp(parent, style="RoundedFrame", padding=10,width=100,height=100)
self.frame_one.pack()
l1=Label(parent,image=self.borderImage).pack()
def popup(self,x,y,width=110,height=120):
self.width=width
self.height=height
self.app = Tk()
self.app.config(bg=self.bg)
self.app.geometry(f"{self.width}x{self.height}+{x}+{y}")
self.app.wm_attributes("-topmost",True)
self.app.overrideredirect(True)
self.app.focus_force()
#self.frame_one = fp(self.app, style="RoundedFrame", padding=10,width=100,height=100)
#self.frame_one.pack()
#l1=Label(self.app,image=self.borderImage).pack()
#self.m.pack_propagate(0)
def destroy(event):
self.app.destroy()
self.app.bind("<FocusOut>",destroy)
if __name__ == "__main__":
root = Tk()
menu = menu(root)
def evt(evt):
menu.popup(evt.x_root,evt.y_root,width=200,height=400)
root.bind("<Button-3>",evt)
root.mainloop()
If i write style for frame like
self.frame_one = fp(parent, style="RoundedFrame", padding=10,width=100,height=100)
in the init() method every thing works fine. If same thing i write in popup methon(where i have just commented out),i got the following error.
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\mishra\AppData\Local\Programs\Python\Python38-32\lib\tkinter\__init__.py", line 1883, in __call__
return self.func(*args)
File "C:\Users\mishra\P_Menu.py", line 64, in evt
menu.popup(evt.x_root,evt.y_root,width=200,height=400)
File "C:\Users\mishra\P_Menu.py", line 51, in popup
self.frame_one = fp(self.app, style="RoundedFrame", padding=10,width=100,height=100)
File "C:\Users\mishra\AppData\Local\Programs\Python\Python38-32\lib\tkinter\ttk.py", line 740, in __init__
Widget.__init__(self, master, "ttk::frame", kw)
File "C:\Users\mishra\AppData\Local\Programs\Python\Python38-32\lib\tkinter\ttk.py", line 557, in __init__
tkinter.Widget.__init__(self, master, widgetname, kw=kw)
File "C:\Users\mishra\AppData\Local\Programs\Python\Python38-32\lib\tkinter\__init__.py", line 2567, in __init__
self.tk.call(
_tkinter.TclError: Layout RoundedFrame not found
Same thing for Lable
l1=Label(self.app,image=self.borderImage).pack()
In the init() section everything works fine but in popup method I got following error.
Traceback (most recent call last):
File "C:\Users\mishra\AppData\Local\Programs\Python\Python38-32\lib\tkinter\__init__.py", line 1883, in __call__
return self.func(*args)
File "C:\Users\mishra\P_Menu.py", line 64, in evt
menu.popup(evt.x_root,evt.y_root,width=200,height=400)
File "C:\Users\mishra\P_Menu.py", line 53, in popup
l1=Label(self.app,image=self.borderImage).pack()
File "C:\Users\mishra\AppData\Local\Programs\Python\Python38-32\lib\tkinter\__init__.py", line 3143, in __init__
Widget.__init__(self, master, 'label', cnf, kw)
File "C:\Users\mishra\AppData\Local\Programs\Python\Python38-32\lib\tkinter\__init__.py", line 2567, in __init__
self.tk.call(
_tkinter.TclError: image "pyimage1" doesn't exist
I want to know how to fix it,cause i want to know logic behind it and use in popup() method.
Any help will be appriciated.
Thank You!
Maybe it's because popup creates a new Tk instance as self.app, but the style belongs to the first Tk instance created by root = Tk(). So a child of the second Tk instance cannot recognize it. Maybe you can try changing self.app = Tk() to self.app = Toplevel() to see if it works?
Okay for last 2 weeks or so I have been teaching myself both opencv and kivy in order to create a UI/Camera System for Autonomous mission from MATE ROV. (I don't feel like explaining about MATE ROV just google it) I have succeeded in creating both the UI and the camera implementation. However, whenever I go to add the cv2.HoughLinesP calculation to find the length of a rectangle in my test image.
[Test Image][1]
I get created by the code running for a short amount of time (usually runs through entire code a couple of times) then I get this.
Traceback (most recent call last):
File "main.py", line 87, in <module>
CamApp().run()
File "/home/mlees/kivy_venv/lib/python3.6/site-packages/kivy/app.py", line 855, in run
runTouchApp()
File "/home/mlees/kivy_venv/lib/python3.6/site-packages/kivy/base.py", line 504, in runTouchApp
EventLoop.window.mainloop()
File "/home/mlees/kivy_venv/lib/python3.6/site-packages/kivy/core/window/window_sdl2.py", line 747, in mainloop
self._mainloop()
File "/home/mlees/kivy_venv/lib/python3.6/site-packages/kivy/core/window/window_sdl2.py", line 479, in _mainloop
EventLoop.idle()
File "/home/mlees/kivy_venv/lib/python3.6/site-packages/kivy/base.py", line 339, in idle
Clock.tick()
File "/home/mlees/kivy_venv/lib/python3.6/site-packages/kivy/clock.py", line 591, in tick
self._process_events()
File "kivy/_clock.pyx", line 384, in kivy._clock.CyClockBase._process_events
File "kivy/_clock.pyx", line 414, in kivy._clock.CyClockBase._process_events
File "kivy/_clock.pyx", line 412, in kivy._clock.CyClockBase._process_events
File "kivy/_clock.pyx", line 167, in kivy._clock.ClockEvent.tick
File "main.py", line 56, in update
for line in buf8:
TypeError: 'NoneType' object is not iterable
I have no clue what is causing this error so if anyone can help me out that would be great. Full Code is below.
from kivy.uix.widget import Widget
from kivy.uix.gridlayout import GridLayout
from kivy.uix.image import Image
from kivy.uix.label import Label
from kivy.clock import Clock
from kivy.graphics.texture import Texture
import cv2
import numpy as np
class CamApp(App):
def build(self):
self.img0 = Image()
self.img1 = Image()
self.img2 = Image()
self.img3 = Image()
layout = GridLayout(cols = 4, rows = 3)
layout.add_widget(self.img0)
layout.add_widget(self.img1)
layout.add_widget(Label(text="HELP"))
layout.add_widget(Label(text="HELP"))
layout.add_widget(self.img2)
layout.add_widget(self.img3)
layout.add_widget(Label(text="HELP"))
layout.add_widget(Label(text="HELP"))
layout.add_widget(Label(text="HELP"))
layout.add_widget(Label(text="HELP"))
layout.add_widget(Label(text="HELP"))
layout.add_widget(Label(text="HELP"))
#opencv2 stuffs
self.capture = cv2.VideoCapture(0)
Clock.schedule_interval(self.update, 1.0/33.0)
return layout
def update(self, dt):
# display image from cam in opencv window
ret, frame = self.capture.read()
# Flip Image and set up first frame
buf1 = cv2.flip(frame, -1)
# Convert main frame to Grayscale
buf3 = cv2.cvtColor(buf1, cv2.COLOR_BGR2GRAY)
# Take Grayscale and add an adaptiveThreshold
buf5 = cv2.adaptiveThreshold(buf3,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY,11,2)
# Edge detection and line detection
buf7 = cv2.Canny(buf3,80,240,3)
buf8 = cv2.HoughLinesP(buf7, 1, np.pi/180, 60, np.array([]), 50, 5)
for line in buf8:
for x1, y1, x2, y2 in line:
cv2.line(buf8, (x1, y1), (x2, y2), (255, 255, 255), 4)
distance_pixels = np.sqrt(np.square(x2 - x1) + np.square(y2 - y1))
print(distance_pixels)
# Necessary to display all the transformations and other bullshit
buf0 = buf1.tostring()
buf2 = buf3.tostring()
buf4 = buf5.tostring()
buf6 = buf7.tostring()
# The next 9 lines are kivy bullshit to get the images on the screen.
texture0 = Texture.create(size=(frame.shape[1], frame.shape[0]), colorfmt='bgr')
texture1 = Texture.create(size=(frame.shape[1], frame.shape[0]), colorfmt='luminance')
texture2 = Texture.create(size=(frame.shape[1], frame.shape[0]), colorfmt='luminance')
texture3 = Texture.create(size=(frame.shape[1], frame.shape[0]), colorfmt='luminance')
texture0.blit_buffer(buf0, colorfmt='bgr', bufferfmt='ubyte')
texture1.blit_buffer(buf2, colorfmt='luminance', bufferfmt='ubyte')
texture2.blit_buffer(buf4, colorfmt='luminance', bufferfmt='ubyte')
texture3.blit_buffer(buf6, colorfmt='luminance', bufferfmt='ubyte')
# display image from the texture
self.img0.texture = texture0
self.img1.texture = texture1
self.img2.texture = texture2
self.img3.texture = texture3
# Here's the running shit.
if __name__ == '__main__':
CamApp().run()
cv2.destroyAllWindows()
Thanks in advance!
This error is arising because in some case, no line is found by HoughLinesP() function thus "buf8" have value "None" at those instances.
Add a line before starting the for loop to check if "buf8" is "None" or not. If not None process, else break the process.
import sys
from PyQt5.QtWidgets import *
from matplotlib.figure import Figure
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib import rc
rc("text", usetex=True)
app = QApplication(sys.argv)
fen = QDialog()
figure = Figure()
canvas = FigureCanvas(figure)
text_edit = QTextEdit()
list_widget = QListWidget()
layout = QHBoxLayout()
layout.addWidget(canvas)
layout.addWidget(text_edit)
fen.setLayout(layout)
def change():
text = figure.suptitle(
r'{}'.format(text_edit.toPlainText()),
x=0.0,
y=1.0,
horizontalalignment='left',
verticalalignment='top'
)
canvas.draw()
text_edit.textChanged.connect(change)
fen.show()
app.exec_()
I have this error:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/matplotlib/texmanager.py", line 486, in make_png
stderr=subprocess.STDOUT)
File "/usr/lib/python3.6/subprocess.py", line 356, in check_output
**kwargs).stdout
File "/usr/lib/python3.6/subprocess.py", line 438, in run
output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['dvipng', '-bg', 'Transparent', '-D', '100.0', '-T', 'tight', '-o', 'b31418787d5e331336f86388cc930ab9.png', 'c073de3d59bf9cbb888f5b9c550ef4f8.dvi']' returned non-zero exit status 1.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/loic/Application_math/test.py", line 31, in change
canvas.draw()
File "/usr/lib/python3/dist-packages/matplotlib/backends/backend_qt5agg.py", line 127, in draw
super(FigureCanvasQTAggBase, self).draw()
File "/usr/lib/python3/dist-packages/matplotlib/backends/backend_agg.py", line 430, in draw
self.figure.draw(self.renderer)
File "/usr/lib/python3/dist-packages/matplotlib/artist.py", line 55, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "/usr/lib/python3/dist-packages/matplotlib/figure.py", line 1299, in draw
renderer, self, artists, self.suppressComposite)
File "/usr/lib/python3/dist-packages/matplotlib/image.py", line 138, in _draw_list_compositing_images
a.draw(renderer)
File "/usr/lib/python3/dist-packages/matplotlib/artist.py", line 55, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "/usr/lib/python3/dist-packages/matplotlib/text.py", line 762, in draw
mtext=mtext)
File "/usr/lib/python3/dist-packages/matplotlib/backends/backend_agg.py", line 250, in draw_tex
Z = texmanager.get_grey(s, size, self.dpi)
File "/usr/lib/python3/dist-packages/matplotlib/texmanager.py", line 545, in get_grey
pngfile = self.make_png(tex, fontsize, dpi)
File "/usr/lib/python3/dist-packages/matplotlib/texmanager.py", line 493, in make_png
exc.output.decode("utf-8"))))
RuntimeError: dvipng was not able to process the following string:
b''
Here is the full report generated by dvipng:
c073de3d59bf9cbb888f5b9c550ef4f8.dvi: No such file or directory
This is dvipng 1.16 Copyright 2002-2015, 2019 Jan-Ake Larsson
rc("text", usetex=True)
This line causes the error but I don't see how to correct it.
I tried to install/uninstall MiKTeX 10 times and nothing changes I still have the error.
Same issue here RuntimeError: LaTeX was not able to process the following string: r'lb' But no solution for me
I found what doesn't fit.
It's just the blank lines.
There's a way to pass empty lines? if I can't air it out its not very useful ^^
I would like to generate a jpeg or png file using the Pyx module. I found
pyx.canvas.writeGSfile() which I tried to use in the following code:
from pyx import *
def mark(x, y):
return path.circle(x, y, 0.1)
if __name__ == '__main__':
c = canvas.canvas()
# r = 70
f = trafo.scale(0.7, 1)
circle = path.circle(0, 0, 2)
a, b = circle.split([0, 2])
c.stroke(a, [style.linewidth.Thick, f])
d1 = f.apply(*circle.at(0.5*circle.arclen()))
d2 = f.apply(*circle.at(circle.arclen()))
c.fill(mark(*d1))
c.fill(mark(*d2))
c.writeGSfile('test.jpeg')
But it spits back the following error:
Traceback (most recent call last):
File "/Python/pyx/test.py", line 19, in <module>
c.writeGSfile('test.png')
File "\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pyx\canvas.py", line 474, in writeGSfile
p = config.Popen(cmd, stdin=config.PIPE)
File "\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pyx\config.py", line 218, in Popen
return subprocess.Popen(cmd, *args, **kwargs)
File "\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 997, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
I tried to debug but I'm having trouble understanding the processing.py section. Any ideas?
You need to have ghostscript installed (gs) to generate bitmap output.
I have the following script to generate a figure with matplotlib:
# -*- coding: utf-8 -*-
import matplotlib.pyplot as plt
import numpy as np
import math
from matplotlib import rc
rc('font',**{'family':'serif'})
rc('text', usetex=True)
rc('text.latex',unicode=True)
rc('text.latex',preamble=r'\usepackage[utf8]{inputenc}')
rc('text.latex',preamble=r'\usepackage[russian]{babel}')
def figsize(wcm,hcm): plt.figure(figsize=(wcm/2.54,hcm/2.54))
figsize(13,9)
x = np.linspace(0,2*math.pi,100)
y = np.sin(x)
plt.plot(x,y,'-')
plt.xlabel(u"Ось абсцисс")
plt.show()
It works fine and the figure is rendered correctly. But when I'm trying to save it to pdf, I get the following error:
Traceback (most recent call last):
File "C:\Path\rus pics\___test_rus.py", line 22, in <module>
plt.savefig(u"c:/fig.pdf")
File "C:\Python35\lib\site-packages\matplotlib\pyplot.py", line 688, in savefig
res = fig.savefig(*args, **kwargs)
File "C:\Python35\lib\site-packages\matplotlib\figure.py", line 1565, in savefig
self.canvas.print_figure(*args, **kwargs)
File "C:\Python35\lib\site-packages\matplotlib\backend_bases.py", line 2232, in print_figure
**kwargs)
File "C:\Python35\lib\site-packages\matplotlib\backends\backend_pdf.py", line 2536, in print_pdf
self.figure.draw(renderer)
File "C:\Python35\lib\site-packages\matplotlib\artist.py", line 61, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "C:\Python35\lib\site-packages\matplotlib\figure.py", line 1159, in draw
func(*args)
File "C:\Python35\lib\site-packages\matplotlib\artist.py", line 61, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "C:\Python35\lib\site-packages\matplotlib\axes\_base.py", line 2324, in draw
a.draw(renderer)
File "C:\Python35\lib\site-packages\matplotlib\artist.py", line 61, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "C:\Python35\lib\site-packages\matplotlib\axis.py", line 1120, in draw
self.label.draw(renderer)
File "C:\Python35\lib\site-packages\matplotlib\artist.py", line 61, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "C:\Python35\lib\site-packages\matplotlib\text.py", line 792, in draw
mtext=mtext)
File "C:\Python35\lib\site-packages\matplotlib\backends\backend_pdf.py", line 1866, in draw_tex
psfont = self.tex_font_mapping(dvifont.texname)
File "C:\Python35\lib\site-packages\matplotlib\backends\backend_pdf.py", line 1568, in tex_font_mapping
return self.tex_font_map[texfont]
File "C:\Python35\lib\site-packages\matplotlib\dviread.py", line 701, in __getitem__
result = self._font[texname.decode('ascii')]
AttributeError: 'str' object has no attribute 'decode'
The error arises only if I use cyrillic letters in labels.
The problem was solved by installing cm-super package with missing larm1200 font. Matplotlib developers, thanks for help!
Using XeLaTex turned out to be a nice workaround. It has its own issues (for example, XeLaTex fails on figures with fill_between), but still it allowed to get cyrillic letters in labels.
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function, unicode_literals)
import matplotlib as mpl
mpl.use("pgf")
pgf_with_custom_preamble = {
"font.family": "serif", # use serif/main font for text elements
"text.usetex": True, # use inline math for ticks
"pgf.rcfonts": False, # don't setup fonts from rc parameters
"pgf.preamble": [
"\\usepackage{units}", # load additional packages
"\\usepackage{metalogo}",
"\\usepackage{unicode-math}", # unicode math setup
r"\setmathfont{xits-math.otf}",
r"\setmainfont{DejaVu Serif}", # serif font via preamble
]
}
mpl.rcParams.update(pgf_with_custom_preamble)
import matplotlib.pyplot as plt
import numpy as np
import math
def figsize(wcm,hcm): plt.figure(figsize=(wcm/2.54,hcm/2.54))
figsize(13,9)
x = np.linspace(0,2*math.pi,100)
y = np.sin(x)
plt.plot(x,y,'-')
plt.xlabel(u"Ось абсцисс")
#plt.show()
plt.savefig(u"d:/fig.pdf")