matplotlib

Changing color of bar plot if value is less than zero and fill white space

两盒软妹~` 提交于 2021-01-28 08:16:31
问题 I have created a DataFrame: df.tail(20) Speed 130 -0.000272 131 -0.000219 132 -0.000178 133 -0.000234 134 -0.000261 135 -0.000281 136 -0.000244 137 -0.000255 138 -0.000290 139 -0.000210 140 -0.000216 141 -0.000209 142 -0.000139 143 -0.000060 144 0.000007 145 0.000043 146 0.000068 147 0.000093 148 -0.000025 149 -0.000005 I am using a barchart to draw barplot: ind = np.arange(len(df)) ax.bar(ind, df['Speed'], width=0.5, color="r") What I am trying to do is changing bar colors to red if values

How do I get more columns of xticklabels

不想你离开。 提交于 2021-01-28 08:11:59
问题 me very new to programming I have problem with bar chart. Here is my bar chart: import numpy as np import matplotlib.pyplot as plt N = 3 Start_means = (100, 50, 50) Start_std = (2, 3, 4) ind = np.arange(N) # the x locations for the groups width = 0.35 # the width of the bars fig, ax = plt.subplots() rects1 = ax.bar(ind, Start_means, width, color='xkcd:cyan', yerr=Start_std) End_means = (80, 30, 30) End_std = (3, 5, 2) rects2 = ax.bar(ind + width, End_means, width, color='xkcd:red', yerr=End

Contour in Python

限于喜欢 提交于 2021-01-28 08:01:00
问题 How Z is calcutalted in from matplotlib.pyplot import contour contour([X, Y,] Z, [levels], **kwargs) to draw a contour? I know that Z means: The height values over which the contour is drawn. But is it drawn by calculating a standard deviation or something like that? An average between each point I have? 回答1: Z represents a quantity dependent on both X and Y axes. If X and Y represent a plane, Z can be thought of as a surface, whose point height depends on the X and Y coordinates of that

Basemap error: module object is not callable

痞子三分冷 提交于 2021-01-28 08:00:32
问题 I am trying to learn how to use basemap in python. I used the following site for learning http://www.datadependence.com/2016/06/creating-map-visualisations-in-python/. but when I typed the following import matplotlib.pyplot as plt import matplotlib.cm import basemap fig,ax=plt.subplots(figsize=(10,20)) m=basemap(resolution='c',projection='merc',lat_0=54.5,lon_0=-4.36,llcrnrlon=-6.,llcrnrlat=49.5,urcrnrlon=2.,urcrnrlat=55.2) m.drawmapboundary(fill_color='#46bcec') m.fillcontinents(color='

annotate text to axes and align as a circle

半腔热情 提交于 2021-01-28 07:58:42
问题 I am trying to plot text on axes and align this text to a circle. More precisely there are points with different coordiantes (x,y) which are located inside this circle and created with: ax.scatter(x,y,s=100) I want to connect and label each point (Cnameb) with the circle. The coordinates of the text are defined with (xp,yp). Thus the arrows between the points and the circle are different in length but the overall distance between the center and the circle is the same as the following figure

Matplotlib axis text coordinates inconsistency?

筅森魡賤 提交于 2021-01-28 07:51:52
问题 I'm working on a piece of code to automatically align x-axis labels for a variable number of subplots. When I started having trouble setting label positions manually, I checked to be sure I could just transform from one set of coordinates to the other without changing anything, with a code snippet like this: # xaxes is a list of Axes objects textCoords = [ax.xaxis.get_label().get_position() for ax in xaxes] newCoords = [ax.transAxes.inverted().transform(ax.xaxis.get_label().\ get_transform()

Choosing a box of data points from a plot

三世轮回 提交于 2021-01-28 07:42:47
问题 I have a catalogue contains three columns and I would like to read them in an array and exclude some of data-points from my catalogue by choosing them from two different plots. If I would call the columns of my catalogue 'm' , 'rh' , and 'rg' , I would like to exclude data-points by choosing different boxes in a 'm-rh' diagram and 'm-rg' plot. How should it be done? I came across this examples but it doesn't return any values like a numpy array ? Any help contains where should I start or how

Explain matplotlib contourf function

感情迁移 提交于 2021-01-28 07:21:41
问题 I am trying to plot a decision region (based on the output of a logistic regression) with matplotlib contourf funtion. The code I am using: subplot.contourf(x2, y2, P, cmap=cmap_light, alpha = 0.8) where x2 and y2 are two 2D matrices generated via numpy meshgrids. P is computed using P = clf.predict(numpy.c_[x2.ravel(), y2.ravel()]) P = P.reshape(x2.shape) Each element of P is a boolean value based on the output of the logistic regresssion. The rendered plot looks like this My question is how

Colour the x-values and show in legend instead of as ticks, in matplotlib (or seaborn)

…衆ロ難τιáo~ 提交于 2021-01-28 07:16:09
问题 I have a large df which I've grouped to plot in a bar chart. I made this mock df to show what I mean. (And I had way too much fun creating it...) my = pd.DataFrame( {'names': ['Andrea', 'Donna', 'Kelly', 'Brenda', 'Allison', 'Jo', 'Amanda', 'Jane', 'Kerry', 'Abby', 'Elizabeth', 'Haleh'], 'episodes': [ 147, 292, 292, 111, 160, 111, 199, 172, 250, 189, 160,184 ], 'tv-show' : ['Beverly Hills, 90210', 'Beverly Hills, 90210', 'Beverly Hills, 90210', 'Beverly Hills, 90210', 'Melrose place',

How to change the position of a single swarm group

一世执手 提交于 2021-01-28 06:58:39
问题 I am plotting a grouped bar plot on which I overlay a swarmplot and errorbars. One of the groups only have one bar, which I want to appear (with the swarm and the errorbar) in the middle of the location allocated to this group of bars. I managed to move the bar and the errorbar, but not sure how to move the swarm. Here is the code I have: import seaborn as sns import matplotlib.pyplot as plt mypallet = sns.color_palette([(190/256,7/256, 18/256),(127/256, 127/256, 127/256)]) import itertools