matplotlib

Drawing histogram of probability density function of a matrix in python [closed]

情到浓时终转凉″ 提交于 2021-01-29 20:12:30
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 5 days ago . Improve this question I have a 2D matrix of p-values. I want to draw a histogram of the pdf of this 2D matrix. How can I do that? 回答1: Just so you know: Seaborn's distplot does all of this. import seaborn as sns, numpy as np sns.set_palette("cividis"); np.random.seed(0) x = np.random.randn(100) ax =

Shade area in plot with datetime on xaxis (axhspan, matplotlib) in python

依然范特西╮ 提交于 2021-01-29 18:44:46
问题 I have a pd df like that with around 6000 entries per column: datetime value flag date 0 2015-01-01 07:00:00 0.018013 0.0 2015-01-01 1 2015-01-01 07:06:00 0.101957 1.0 2015-01-01 2 2015-01-01 07:12:00 0.141712 1.0 2015-01-01 3 2015-01-01 07:18:00 0.178875 0.0 2015-01-01 4 2015-01-01 07:24:00 0.237765 0.0 2015-01-01 ... ... ... ... Now I want to plot the datetime on the x-axis and the value on the y-axis and shade the area when the flag = 0. but not a line (with axvline it works) but the whole

Text alignment using format in matplotlib legend

不打扰是莪最后的温柔 提交于 2021-01-29 18:37:30
问题 I'm trying to get two words aligned in a legend in matplotlib. With the print statement I can do this using the tools available to format (< for left alignment, > for right alignment), but in the legend this has a different result. import matplotlib.pyplot as plt import numpy as np str1 = r'{:<18} {:>12}'.format('HadGEM2-ES'+',', r'$\lambda$') str2 = r'{:<18} {:>12}'.format('inmcm4'+',', r'$\lambda$') print(str1) print(str2) plt.plot(np.arange(10), label=str1) plt.plot(0.8*np.arange(10),

Matplotlib: GRID and COLORMAP with TRISURF

前提是你 提交于 2021-01-29 17:56:46
问题 I want to put a grid on my surface but it doesn't work even with linewidth different from zero, also I would like to plot a colormap that changes the color with Z axis, so the walls should appear with the same color cos they are points at 0.5 in Z. Hope somebody can help me, thanks. This is the part of my code I'm having problem with: fig = plt.figure() ax = Axes3D(fig) surf = ax.plot_trisurf(x, y, z, cmap=plt.cm.get_cmap('jet',4), shade=False,linewidth=0.1, antialiased=False ) This is my

how to write a crosstab query in pandas and python with visualization

ε祈祈猫儿з 提交于 2021-01-29 17:40:36
问题 this function display the crosstab table and visualize the result using matplotlib. def event_mouhafaza(self,df): df_event_mohafazat_crosstab = pd.crosstab(df['event_mohafaza'],df['event_type']) print(df_event_mohafazat_crosstab) data = [] #use for loop on every zoo name to create bar data for x in df_event_mohafazat_crosstab.columns: data.append(go.Bar(name=str(x), x=df_event_mohafazat_crosstab.index, y=df_event_mohafazat_crosstab[x])) layout = go.Layout( title = "Event type over Location",

How do I plot an updating numpy ndarray in real time using matplotlib?

☆樱花仙子☆ 提交于 2021-01-29 17:29:41
问题 I have a numpy array which I initialized outside the loop using np.zeros. This array is updated using some function inside a for a loop. I wish to plot the array as it changes with each iteration. Most of the answers I have seen here are for lists and not ndarrays. I have seen the following links. Some of them I have tried to modify for my purpose but to no avail. How to update a plot in matplotlib? https://github.com/stsievert/python-drawnow/blob/master/drawnow/drawnow.py @Scott Sievert, I

Plotting with multiple y values with subplot and groupby

扶醉桌前 提交于 2021-01-29 17:28:44
问题 I have a df . See below for the head: Country Date suspected case confirmed cases suspected deaths confirmed deaths 0 Guinea 2014-08-29 25.0 141.0 482.0 648.0 1 Nigeria 2014-08-29 3.0 1.0 15.0 19.0 2 Liberia 2014-08-29 382.0 674.0 322.0 1378.0 By using df.groupby('Country') I want to plot the suspected case against the confirmed case using the Date column for the xaxis . Plotting these as (5, 2) subplots What I've done so far hasn't quite got it yet: fig, ax = plt.subplots(2, 5, sharey=True)

changing the colour based on the graphs positions matplotlib

独自空忆成欢 提交于 2021-01-29 17:24:27
问题 With the dataset below i am trying to plot a line graph on matplotlib. I am trying to make a function that looks at the previous number and checks whether the current number is higher. If the current function is bigger it would draw a blue line going to the next point such as it would draw a blue line between (1,100) and (2,9313) . If its not greater (6,203542) and (7,203542) , a red line would be drawn. import matplotlib.pyplot as plt x_long = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] L

Convert x-axis from days to month in matplotlib

独自空忆成欢 提交于 2021-01-29 16:58:45
问题 i have x-axis which is in terms of days (366 days Feb was taken as 29 days) but instead I want to convert it in terms of months (Jan - Dec). What should i do... def plotGraph(): line, point = getXY() plt.plot(line['xlMax'], c='orangered', alpha=0.5, label = 'Minimum Temperature (2005-14)') plt.plot(line['xlMin'], c='dodgerblue', alpha=0.5, label = 'Minimum Temperature (2005-14)') plt.scatter(point['xsMax'].index, point['xsMax'], s = 10, c = 'maroon', label = 'Record Break Minimum (2015)') plt

contourf plots whitespace over finite data. Past answers do not correct

雨燕双飞 提交于 2021-01-29 16:37:23
问题 Comments in code include proposed fix using np.linespace limits. This does not correct the problem in spite of the following given answer from the question "contourf() plots white space over finite data":If you want to make sure they all data is included you may define you own levels to use plt.contourf(x, y, Z, np.linspace(Z.min(), Z.max(), 100)) The provided solution was thought to work then found not to in the older post. The statement was made the problem was not seen or not repeatable so