matplotlib

Ignoring negative values when using np.log(array)

帅比萌擦擦* 提交于 2021-01-21 09:18:23
问题 When taking the log of a specific column within a numpy array, i.e., logSFROIIdC = np.log(data_dC[:, 9]) the compiler returns the error: -c:13: RuntimeWarning: divide by zero encountered in log. Now, I know why this happens, i.e., log(-1) = Math Error. However, I want to be able to call something or write some code which then skips any value in the array which would cause this error, then ignoring that row altogether. Allowing that data column to be usable again. I have tried various methods

How can I plot the probability density function for a fitted Gaussian mixture model under scikit-learn?

▼魔方 西西 提交于 2021-01-21 06:25:52
问题 I'm struggling with a rather simple task. I have a vector of floats to which I would like to fit a Gaussian mixture model with two Gaussian kernels: from sklearn.mixture import GMM gmm = GMM(n_components=2) gmm.fit(values) # values is numpy vector of floats I would now like to plot the probability density function for the mixture model I've created, but I can't seem to find any documentation on how to do this. How should I best proceed? Edit: Here is the vector of data I'm fitting. And below

How to draw a tree more beautifully in networkx

感情迁移 提交于 2021-01-21 05:16:09
问题 If I make a tree using networkx and draw it, the nodes overlap. Is there a way to draw it so there is no overlap? import matplotlib.pyplot as plt import networkx as nx T = nx.generators.balanced_tree(2, 5) nx.draw(T) plt.show() 回答1: I am no expert in this, but here is code that uses the pydot library and its graph_viz dependency. These libraries come with Anaconda Python but are not installed by default, so first do this from the command prompt: conda install pydot Then here is code adapted

How to draw a tree more beautifully in networkx

扶醉桌前 提交于 2021-01-21 05:15:40
问题 If I make a tree using networkx and draw it, the nodes overlap. Is there a way to draw it so there is no overlap? import matplotlib.pyplot as plt import networkx as nx T = nx.generators.balanced_tree(2, 5) nx.draw(T) plt.show() 回答1: I am no expert in this, but here is code that uses the pydot library and its graph_viz dependency. These libraries come with Anaconda Python but are not installed by default, so first do this from the command prompt: conda install pydot Then here is code adapted

How can I get my contour plot superimposed on a basemap

别说谁变了你拦得住时间么 提交于 2021-01-21 04:13:10
问题 This is a question I asked several months ago and am still struggling to come to a solution. My code gives me a basemap and a contour plot side by side (but printing to file only gives the contour plot), but I want them superimposed. The best solution would the one here https://gist.github.com/oblakeobjet/7546272 but this does not show how to introduce the data, and it is difficult when you are learning from scratch online. Without tiring very kind people, I hope the solution is easy as

How can I get my contour plot superimposed on a basemap

耗尽温柔 提交于 2021-01-21 04:12:32
问题 This is a question I asked several months ago and am still struggling to come to a solution. My code gives me a basemap and a contour plot side by side (but printing to file only gives the contour plot), but I want them superimposed. The best solution would the one here https://gist.github.com/oblakeobjet/7546272 but this does not show how to introduce the data, and it is difficult when you are learning from scratch online. Without tiring very kind people, I hope the solution is easy as

How can I get my contour plot superimposed on a basemap

自闭症网瘾萝莉.ら 提交于 2021-01-21 04:10:26
问题 This is a question I asked several months ago and am still struggling to come to a solution. My code gives me a basemap and a contour plot side by side (but printing to file only gives the contour plot), but I want them superimposed. The best solution would the one here https://gist.github.com/oblakeobjet/7546272 but this does not show how to introduce the data, and it is difficult when you are learning from scratch online. Without tiring very kind people, I hope the solution is easy as

How can I generate more colors on pie chart matplotlib

↘锁芯ラ 提交于 2021-01-21 03:51:30
问题 I am having more then 40 items to show in my chart. I have only 10 colours that repeatedly are shown on the chart. How can I generate more colors. plt.pie(f,labels=labels,autopct='%1.1f%%', startangle=90,shadow=True) I should add "color=colors" where colors is generated infinitely ? 回答1: You need colors argument, beside that you can use some color maps from cm . >>> import matplotlib.pyplot as plt >>> from matplotlib import cm >>> import numpy as np >>> a=np.random.random(40) >>> cs=cm.Set1

How can I generate more colors on pie chart matplotlib

天大地大妈咪最大 提交于 2021-01-21 03:50:07
问题 I am having more then 40 items to show in my chart. I have only 10 colours that repeatedly are shown on the chart. How can I generate more colors. plt.pie(f,labels=labels,autopct='%1.1f%%', startangle=90,shadow=True) I should add "color=colors" where colors is generated infinitely ? 回答1: You need colors argument, beside that you can use some color maps from cm . >>> import matplotlib.pyplot as plt >>> from matplotlib import cm >>> import numpy as np >>> a=np.random.random(40) >>> cs=cm.Set1

How can I generate more colors on pie chart matplotlib

倖福魔咒の 提交于 2021-01-21 03:49:30
问题 I am having more then 40 items to show in my chart. I have only 10 colours that repeatedly are shown on the chart. How can I generate more colors. plt.pie(f,labels=labels,autopct='%1.1f%%', startangle=90,shadow=True) I should add "color=colors" where colors is generated infinitely ? 回答1: You need colors argument, beside that you can use some color maps from cm . >>> import matplotlib.pyplot as plt >>> from matplotlib import cm >>> import numpy as np >>> a=np.random.random(40) >>> cs=cm.Set1