matplotlib

Seaborn Confusion Matrix (heatmap) 2 color schemes (correct diagonal vs wrong rest)

谁说我不能喝 提交于 2021-02-04 16:43:12
问题 Background In a confusion matrix, the diagonal represents the cases that the predicted label matches the correct label. So the diagonal is good, while all other cells are bad. To clarify what is good and what is bad in a CM for non-experts, I want to give the diagonal a different color than the rest. I want to achieve this with Python & Seaborn . Basically I'm trying to achieve what this question does in R (ggplot2 Heatmap 2 Different Color Schemes - Confusion Matrix: Matches in Different

Animating a 3D vector with matplotlib

此生再无相见时 提交于 2021-02-04 16:37:45
问题 I need to animate both the magnitude and the position of a vector arrow in a 3D figure with matplotlib. As far as I can tell, I cannot animate the position of the vectors with Axes3D.quiver and there is no matplotlib.pyplot.arrow for a 3D figure. Is there a way to do this or do I need to look at other options? 回答1: quiver does not have an updating function, but you can easily remove an old quiver and plot a new one in each frame. import numpy as np import matplotlib.pyplot as plt from mpl

How to convert a grid-like matplotlib plot to a smooth gradient like surface?

人走茶凉 提交于 2021-02-04 16:24:43
问题 I am trying to plot a 2D numpy array using imshow function from matplotlib.pyplot (it is the plot of a U-matrix generated using the codebook of a self organizing map). The plot is being generated by the following line: matplotlib.pyplot.imshow(umat, cmap=plt.cm.get_cmap('RdYlBu_r'), alpha=1) Here, umat is the 2D numpy array that I am trying to plot. Here is the plot that is generated: It shows each node (point) as a distinct square. I would like to generate something like this , showing a

Pandas plot bar chart over line

允我心安 提交于 2021-02-04 16:23:45
问题 I'm trying to plot a bar and a line on the same graph. Here is what works and what does not work. Would anyone please explain why? What does NOT work: df = pd.DataFrame({'year':[2001,2002,2003,2004,2005], 'value':[100,200,300,400,500]}) df['value1']= df['value']*0.4 df['value2'] = df['value']*0.6 fig, ax = plt.subplots(figsize = (15,8)) df.plot(x = ['year'], y = ['value'], kind = 'line', ax = ax) df.plot(x = ['year'], y= ['value1','value2'], kind = 'bar', ax = ax) But somehow it works when I

Draw / Create Scatterplots of datasets with NaN

百般思念 提交于 2021-02-04 15:18:05
问题 I want to draw a scatter plot using pylab, however, some of my data are NaN , like this: a = [1, 2, 3] b = [1, 2, None] pylab.scatter(a,b) doesn't work. Is there some way that I could draw the points of real value while not displaying these NaN value? 回答1: Things will work perfectly if you use NaN s. None is not the same thing. A NaN is a float. As an example: import numpy as np import matplotlib.pyplot as plt plt.scatter([1, 2, 3], [1, 2, np.nan]) plt.show() Have a look at pandas or numpy

Image size of 1005x132589 pixels is too large. It must be less than 2^16 in each direction

陌路散爱 提交于 2021-02-04 14:28:26
问题 I am using matplotlib.pyplot to plot a graph from a Dataframe. I want to show the height of the bar upon each rectangle and am using Text() . For normalising the y-axis, I have taken the log. Below is my code, I am getting error Image size of 1005x132589 pixels is too large. It must be less than 2^16 in each direction When I am not using plt.yscale('log') then the code is working fine. According to some suggestions, I have restarted my kernel too, but still getting this issue. Any suggestions

matplotlib bar plot add legend from categories dataframe column

。_饼干妹妹 提交于 2021-02-04 13:21:53
问题 I try to add the legend which should, according to my example, output: a red square with the word fruit and a green square with the word veggie. I tried several things (the example below is just 1 of the many trials), but I can't get it work. Can someone tell me how to solve this problem? import pandas as pd from matplotlib import pyplot as plt data = [['apple', 'fruit', 10], ['nanaba', 'fruit', 15], ['salat','veggie', 144]] data = pd.DataFrame(data, columns = ['Object', 'Type', 'Value'])

Pyplot errorbar keeps connecting my points with lines?

☆樱花仙子☆ 提交于 2021-02-04 13:16:51
问题 I am having trouble getting these lines between my data points to go away! It seems to be whenever I try to add error bars it does this. If you look at the graphs, the first is without the errorbar line, and the second is with it. Is this a usual side effect of pyplot errorbar? Does anyone know why it does this, or how to make it go away? plt.figure() plt.scatter(x, y, label = 'blah') plt.errorbar(x, y, yerr = None, xerr = x_err) plt.plot(x, f) #this is a line of best fit 回答1: You can set the

Plotting stochastic processes in Python

安稳与你 提交于 2021-02-04 12:33:36
问题 Say I have a stochastic process defined between [0... N] , e.g. N=50 . For every location, I have several samples (e.g. m=100 samples) (representing my sampling distribution at each location). One way to look at this is as a numpy 2D array of size (m,N) . How can I plot this intuitively in matplotlib ? One possibility is to plot the process as a 1D plot along with an envelope of varying thickness and shade that captures the density of these distributions, something along the lines of what I

How to tell Homebrew to install inside virtualenv?

天大地大妈咪最大 提交于 2021-02-04 12:27:10
问题 Here's my problem. I can't install MatPlotLib both via pip and from source (Matplotlib installation on Mavericks). I tried brew install matplotlib and the installation successfully ended. However, it installed MatPlotLib globally and not inside the currently activated VirtualEnv. Is it possible to tell brew to install a package inside the current VirtualEnv? 回答1: I help maintain the homebrew-python tap. This is not and will not be supported and there probably isn't an easy way to do it. This