matplotlib

RuntimeError: LaTeX was not able to process the following string: r'lb'

我怕爱的太早我们不能终老 提交于 2021-01-28 11:39:31
问题 There are similar questions on here, but none seem to capture all this problem. If I copy-and-paste the demo code on matplotlib website using a Jupyter Notebook or Anaconda Python on Windows: """ Demo of TeX rendering. You can use TeX to render all of your matplotlib text if the rc parameter text.usetex is set. This works currently on the agg and ps backends, and requires that you have tex and the other dependencies described at http://matplotlib.org/users/usetex.html properly installed on

Placing text around the circle

删除回忆录丶 提交于 2021-01-28 11:10:17
问题 Using pyplot circle function I made a circle, then I have used text function to place the text(parameters) across the circle(PLOT ATTACHED) but the thing is if let's say I want to list out only 6 or say 11 parameters equally spaced across the circle I'll have to chage the coordinates as well as the rotation in text (and the coordinates and rotation value has been manually set). I want something that'll automate these things like given a number of parameter it will place parameter with equal

Matplotlib: how to set only min and max values for tics

亡梦爱人 提交于 2021-01-28 11:02:41
问题 I have pretty similar code to plot: plt.plot(df_tags[df_tags.detailed_tag == tag]['week'], df_tags[df_tags.detailed_tag == tag].tonality) Output: But I want leave only min and max values for x axis this way: plt.plot(df_tags[df_tags.detailed_tag == tag]['week'], df_tags[df_tags.detailed_tag == tag].tonality) plt.xticks([df_tags['week'].min(), df_tags['week'].max()]) print (df_tags['week'].min(), df_tags['week'].max()) With no luck, he puts second week as a last one, but why and how to fix it:

Seaborn heatmap with numerical axes

夙愿已清 提交于 2021-01-28 10:41:00
问题 I want to overlay a heatmap with a second chart (a KDEplot, but for this example I'll use a scatterplot, since it shows the same issue). Seaborn heatmaps have categorical axes, so overlaying a chart with numerical axes doesn't line up the two charts properly. Example: df = pd.DataFrame({2:[1,2,3],4:[1,3,5],6:[2,4,6]}, index=[3,6,9]) df 2 4 6 3 1 1 2 6 2 3 4 9 3 5 6 fig, ax1 = plt.subplots(1,1) sb.heatmap(df, ax=ax1, alpha=0.1) Overlaying this with a scatterplot: fig, ax1 = plt.subplots(1,1)

Adding labels on legend does not work, using matplotlib

醉酒当歌 提交于 2021-01-28 09:50:33
问题 I have the following dataframe import pandas as pd import matplotlib.pyplot as plt df = pd.DataFrame({'var': ['bid', 'on', 'off', 'bid', 'on', 'off'], 'aud': ['H', 'H', 'H', 'L', 'L', 'L'], 'eff': [0.1, 0.2, 0.3, 0.01, 0.02, 0.03], 'spend': [10, 20, 30, 1, 2, 3], 'marg': [0.001, 0.002, 0.003, 0.0001, 0.0002, 0.0003]}) My end goal is to create a bubble plot, with specific color s for every var , the marg on the y_axis , the eff on the x_axis of the plot and the size of the bubbles to be equal

How do I change the axes' units in a figure?

£可爱£侵袭症+ 提交于 2021-01-28 09:37:42
问题 I'm making figures of some galaxies velocities with matplotlib , from some .fits files. The problem is that the axes in the figure show the galaxy's size in pixels, and I want to display them as Declination and RightAcension (in angle units). I already know that each pixel has a size of 0.396 arcseconds. How can I convert pixels to arcseconds in both X and Y axes? The code is the folowing: ############################################################################## # Generally the image

How to position a matplotlib patch outside of the axes range (so that it could be next to the title, or legend, or anywhere on the figure)

强颜欢笑 提交于 2021-01-28 09:00:53
问题 Given the following code: fig, ax = plt.subplots() ax.scatter([1, 2, 3, 4, 5], [34, 22, 11, 4, 6], s=100) _ = ax.text(x=0, y=1.1, s="This is some text", transform=ax.transAxes, fontsize=20) rect = mpl.patches.Rectangle( (0.5, 0.5), width=0.05, height=0.05, color="red", transform=ax.transAxes, ) ax.add_patch(rect) Which creates: I would like to add the patch to the following location: So that the plot looks as follows: It seems that I am unable to have patches outside of the axes spines area

Matplotlib: RGBA values should be within 0-1 range

萝らか妹 提交于 2021-01-28 09:00:47
问题 I want to scatter some data points. I wrote: sumy = sum(np.unique(y_train))+1 yy = y_train/sumy plt.scatter( X_lda.iloc[:,0], X_lda.iloc[:,1], c=yy, cmap='rainbow') /usr/local/lib/python3.6/dist-packages/matplotlib/colors.py in to_rgba_array(c, alpha) 277 result[mask] = 0 278 if np.any((result < 0) | (result > 1)): --> 279 raise ValueError("RGBA values should be within 0-1 range") 280 return result 281 # Handle single values. ValueError: RGBA values should be within 0-1 range y_train is an

Matplotlib plotting some characters as blank square

不打扰是莪最后的温柔 提交于 2021-01-28 08:22:15
问题 I'm working on reading some photos and taking the text with OCR. Now I need to rank the text read into some graph in order to see some pattern. But when I try to plot those texts into a graph, I got blank squares in the place of some characters. I'm sharing a example of what I've done with a script: This is an example script: import numpy as np import matplotlib.pyplot as plt fig, ax = plt.subplots() y = [0,1,2,3] group_labels = ['77 7 7 7\r\nlfISldI\r\n\r\n', 'G217\r\nini\r\n\r\n', 'L519\r

Using subplot_kw in matplotlib to create a polar projection in subplots

时光总嘲笑我的痴心妄想 提交于 2021-01-28 08:19:30
问题 I'm trying to create a polar projection using matplotlib.pyplot.subplots() but I get the error projection is not defined when I try to pass a dictionary to matplotlib.pyplot.subplots() My code: import matplotlib.pyplot as plt fig, ax = plt.subplots(nrows=1, ncols=2, subplot_kw={projection:'polar'}) However plt.subplot(1,1,1, projection='polar') works as expected. The documentation for plt.subplots() says that the dictionary in subplot_kw will be passed to add.subplot() which takes projection