matplotlib

Problems With Contours Using Python's matplotlib 3D API

纵然是瞬间 提交于 2021-02-04 20:52:33
问题 I'm trying to do something similar to this 3D example from the docs, but with a point cloud instead of a smooth surface. The example projects 2D contours onto each of the three coordinate planes. This shows that I'm able to do that onto the xy-plane. When I try doing the same onto the other two planes, I get either a weird contour collapsed down to a thin strip, or an exception way beyond my reach in the bowels of matplotlib . Traceback (most recent call last): File ".../matplotlib/backends

Reducing file sizes of PDFs created using matplotlib by changing font embedding

不羁的心 提交于 2021-02-04 19:42:26
问题 I'm using matplotlib to produce PDF figures. However, even the simplest figures produce relatively large files, the MWE below produces a file of almost 1 MB. I've become aware that the large file size is due to matplotlib fully embedding all the used fonts. Since I'm going to produce quite a few plots and would like to reduce the file sizes, I'm wondering: Main question: Is there a way to get matplotlib to embed font subsets instead of the complete fonts? I would also be fine with not

How to add bar and line under the same label in a legend?

扶醉桌前 提交于 2021-02-04 19:04:03
问题 I made a plot with 2 Y axes, where one has a bar chart and the other one lines and I would like to add a common legend for both plots. If I add the following: axis1.legend([(bar1, line1), (bar2, line2)], ['Solution 1', 'Solution 2'], loc='upper left', numpoints=1) I almost get what I want, except for the markers / artists (not sure which term is suitable here), which are overlapping for both solutions as seen here: Is it possible to have the bar artist first and the line artist second, side

Aspect ratio in semi-log plot with Matplotlib

≡放荡痞女 提交于 2021-02-04 18:55:51
问题 When I plot a function in matplotlib, the plot is framed by a rectangle. I want the ratio of the length and height of this rectangle to be given by the golden mean ,i.e., dx/dy=1.618033... If the x and y scale are linear I found this solution using google import numpy as np import matplotlib.pyplot as pl golden_mean = (np.sqrt(5)-1.0)/2.0 dy=pl.gca().get_ylim()[1]-pl.gca().get_ylim()[0] dx=pl.gca().get_xlim()[1]-pl.gca().get_xlim()[0] pl.gca().set_aspect((dx/dy)*golden_mean,adjustable='box')

Matplotlib - Python- GetDist tool - Overlapping 2 triangle plots (triplots) by calling twice the plot function: issue of visible priority between both

谁都会走 提交于 2021-02-04 18:50:46
问题 In python3, I am faced to 2 issues using the tool GetDist tool to produce triplot of covariance matrix. 1) Currently, I can plot 2 covariance matrixes on the same figure by only one call of the plotting function (triangle_plot). Specifying as first input the list of covariance matrix to plot is enough to have the (1 sigma,2 sigma) contours of each matrix. Here an example of triplot produced by 2 covariance matrixes (filled area correspond to 1 sigma confidence level (68%) and shaded to 2

legend alignment in matplotlib

一曲冷凌霜 提交于 2021-02-04 18:39:44
问题 I'm trying to get labels left-aligned and values right-aligned in the legend. In below code, I've tried with format method, but the values are not properly aligned. Any hint/suggestions is greatly appreciated. import matplotlib.pyplot as pl # make a square figure and axes pl.figure(1, figsize=(6,6)) labels = 'FrogsWithTail', 'FrogsWithoutTail', 'DogsWithTail', 'DogsWithoutTail' fracs = [12113,8937,45190, 10] explode=(0, 0.05, 0, 0) pl.pie(fracs, explode=explode, labels=labels, autopct='%1.1f%

Pandas - Style - Background Gradient using other dataframe

℡╲_俬逩灬. 提交于 2021-02-04 18:08:52
问题 I like using the background_gradient as it helps me look at my dataframes in an excel way. But I'm wondering if I there is a way I could map the colors to the figures in another dataframe. For example, something I am keen to do is to color the dataframe using a dataframe of zscores so i can see quickly the value of outliers. A = pd.DataFrame(np.random.randn(6, 3), columns=['a', 'b', 'c']) B = pd.DataFrame(np.random.randn(6, 3), columns=['a', 'b', 'c']) A.style.background_gradient(???) I'm

Finding the maximum of a curve scipy

我是研究僧i 提交于 2021-02-04 17:49:24
问题 I have fitted curve to a set of data points. I would like to know how to find the maximum point of my curve and then I would like to annotate that point (I don't want to use by largest y value from my data to do this). I cannot exactly write my code but here is the basic layout of my code. import matplotlib.pyplot as plt from scipy.optimize import curve_fit x = [1,2,3,4,5] y = [1,4,16,4,1] def f(x, p1, p2, p3): return p3*(p1/((x-p2)**2 + (p1/2)**2)) p0 = (8, 16, 0.1) # guess perameters plt

Finding the maximum of a curve scipy

最后都变了- 提交于 2021-02-04 17:48:13
问题 I have fitted curve to a set of data points. I would like to know how to find the maximum point of my curve and then I would like to annotate that point (I don't want to use by largest y value from my data to do this). I cannot exactly write my code but here is the basic layout of my code. import matplotlib.pyplot as plt from scipy.optimize import curve_fit x = [1,2,3,4,5] y = [1,4,16,4,1] def f(x, p1, p2, p3): return p3*(p1/((x-p2)**2 + (p1/2)**2)) p0 = (8, 16, 0.1) # guess perameters plt

Manually-defined axis labels for Matplotlib imshow()

北城余情 提交于 2021-02-04 17:20:09
问题 The following code: import matplotlib.pyplot as plt import numpy as np data = np.random.randint(0, 100, size=(10, 10)) plt.imshow(data, cmap='jet', interpolation='nearest') plt.show() Gives the following figure: However, instead of the axis labels corresponding to the index in the array, I want to manually define them. For example, instead of the axis labels being (0, 2, 4, 6, 8) as above, I want them to be (0, 10, 20, 30 ...). Here is the code I have tried for this: import matplotlib.pyplot