matplotlib

Matplotllib and Xelatex

时光毁灭记忆、已成空白 提交于 2021-01-28 04:31:06
问题 I tried to find the answer for my question for some time now but could not come up with something that works for me. My question is: How can you use Xelatex to compile text in Matplotlib? I know that there is this page: http://matplotlib.org/users/pgf.html However, I could not come up with something that would work. What I got up to now: import matplotlib as mpl mpl.use("pgf") ## TeX preamble preamble = """ \usepackage{fontspec} \setmainfont{Linux Libertine O} """ params = {"text.usetex":

Small square instead of line in legend?

筅森魡賤 提交于 2021-01-28 04:25:17
问题 To make a custom legend, I currently use the following: handles, labels = plt.gca().get_legend_handles_labels() my_artist = plt.Line2D((0,1),(0,0), color = "blue", linestyle = "-", linewidth = 1) plt.legend([handle for i,handle in enumerate(handles) if i in display]+[my_artist], [label for i,label in enumerate(labels) if i in display]+["My legend"]) It will draw a blue line in the legend box. Instead of a line I would like to have a small blue square (but larger than a simple marker). How to

Highlighting certain nodes/edges in NetworkX - Issues with using zip()

◇◆丶佛笑我妖孽 提交于 2021-01-28 03:59:46
问题 I able to populate network graph using networkx. My problem is when I want to highlight the path (shortest path for example) the graph cannot generate and it will return error below. nx.draw_networkx_edges(Gr,pos,edgelist=path_edges,edge_color='r',width=10) File "/usr/local/lib/python3.6/site-packages/networkx/drawing/nx_pylab.py", line 578, in draw_networkx_edges if not edgelist or len(edgelist) == 0: # no edges! TypeError: object of type 'zip' has no len() I look for solution and this is

Plotting Fourier Transform Of A Sinusoid In Python

笑着哭i 提交于 2021-01-28 03:57:25
问题 The following python program plots a sinusoid: import matplotlib.pyplot as plt import numpy as np # Canvas plt.style.use("ggplot") # Frequency, Oscillations & Range f = int(input("Enter frequency: ")) n_o = int(input("Enter number of oscillations: ")) t_max = n_o/f t = np.linspace(0, t_max, 1000) # Sine y_sin = np.sin(2*np.pi*f*t) # Setting subplots on separate axes fig, axs = plt.subplots(2, 1, constrained_layout = True) # Sine axis axs[0].plot(t, y_sin, color = "firebrick", label = "sin({

Python polar plot: Plot values corresponding to the angle

天大地大妈咪最大 提交于 2021-01-28 03:56:05
问题 I'm trying to plot sensor data, which was recorded with different angles. import pandas as pd import matplotlib.pyplot as plt #create dataframe, each row contains an angle and a corresponding value df = pd.DataFrame(columns = ["angle","value"]) df.angle = [0,5,10,15,20,25,30,35,40,45,50,55,60] df['value'] = df.apply(lambda row: 100 -row.angle/2 , axis=1) print(df) #plotting plt.polar(df['angle'].values,df['value'].values) plt.show() This returns: But I need a plot that shows a value of 100 at

Surface Plot in Python - MemoryError

柔情痞子 提交于 2021-01-28 03:11:51
问题 I'm trying to create a surface plot using coordinates using the following code: from mpl_toolkits.mplot3d import Axes3D from scipy.stats import gaussian_kde fig = plt.figure() ax = Axes3D(fig) X = [] Y = [] XY = np.vstack([X, Y]) x, y = np.meshgrid(X, Y) z = gaussian_kde(XY)(XY).tolist() ax.plot_surface(x, y, z) plt.show() Assume that X and Y are long lists of floating point numbers. However, when I execute the code I get a MemoryError, which traces back to the meshgrid method: in meshgrid

How to clear memory completely of all Matplotlib plots

こ雲淡風輕ζ 提交于 2021-01-28 03:10:18
问题 I have data analysis module that contains functions which call on Matplotlib pyplot API multiple times to generate up to 30 figures in each run. These figures get immediately written to disk after they are generated, and so I need to clear them from memory. Currently, at the end of each of my function, I do import matplotlib.pyplot as plt plt.clf() however I'm not too sure if this statement can actually clear the memory. I'm especially concerned since I see that each time I run my module for

matplotlib: get the subplot layout?

天涯浪子 提交于 2021-01-28 02:58:15
问题 I have a function that creates a grid of similar 2D histograms. So that I can select whether to put this new plot on a pre-existing figure, I do the following: def make_hist2d(x, y, current_fig=False, layout=(1,1,1),*args): if current_fig: fig = _plt.gcf() ax = fig.add_subplot(*layout) # layout=(nrows, ncols, nplot) else: fig, ax = _plt.subplots() H, x, y = np.histogram2d(...) # manipulate the histogram, e.g. column normalize. XX, YY = _np.meshgrid(xedges, yedges) Image = ax.pcolormesh(XX, YY

2x2 Contourf plots sharing the same colorbar

杀马特。学长 韩版系。学妹 提交于 2021-01-28 02:26:46
问题 I would like to add a single color bar on the right side of the following 2x2 plot. import matplotlib.pyplot as plt import numpy as np x = np.linspace(-np.pi*2, np.pi*2, num=50) y = np.linspace(-np.pi*2, np.pi*2, num=50) def fun(x, y, pw1, pw2): X,Y = np.meshgrid(x, y) return (X, Y, np.cos(X*Y)**pw1 + np.sin(X+Y)**pw2) X, Y, f01 = fun(x,y,0,1) X, Y, f10 = fun(x,y,1,0) X, Y, f11 = fun(x,y,1,1) X, Y, f12 = fun(x,y,1,2) fig1, axs = plt.subplots(nrows=2,ncols=2, figsize=(8,8),sharex='col', sharey

Tkinter Matplotlib, backend conflict?

旧巷老猫 提交于 2021-01-28 02:25:16
问题 I'm quite new to python but I've spent my last week trying to code a software to visualize some weavy thingy. The basic cinematic is: the user enters every information needed into a GUI then click proceed and I have an other big function to genereate all the graphics. This was working but the problem was that when I ran the function, which lasts like 2 minutes, the tkinter window was freezing. I read that I should use threads. Then I found this: http://uucode.com/texts/pylongopgui/pyguiapp