matplotlib

colorbar changes the size of subplot in python

做~自己de王妃 提交于 2021-02-16 13:57:10
问题 I use the following code to generate side-by-size images and I need to add colorbar only to the second image in the row. I use the following code for it import matplotlib.pyplot as plt from mpl_toolkits.axes_grid1 import make_axes_locatable import matplotlib.gridspec as gridspec def plotting(x): gs1 = gridspec.GridSpec(1, 2) gs1.update(wspace=0.005, hspace=0.005) plt.subplot(gs1[0]) plt.imshow(x) plt.axis('off') plt.title('dog') ax1 = plt.subplot(gs1[1]) imc = plt.imshow(x, cmap='hot',

Matplotlib - Move labels into middle of pie chart

一个人想着一个人 提交于 2021-02-16 11:21:15
问题 I've got my pie chart working but I noticed that the text boxes for the actual chart doesn't seem to be working correctly. They are just clustered so I was wondering is there any way for me to move the labels into the middle where the white circle is and have the matching colour beside it or not? crimeTypes = dict(crimeData["Crime type"].value_counts()) crimeType = [] totalAmount = [] numberOfCrimes = 14 for key in sorted(crimeTypes, key=crimeTypes.get, reverse=True): crimeType.append(key)

Matplotlib - Move labels into middle of pie chart

隐身守侯 提交于 2021-02-16 11:20:17
问题 I've got my pie chart working but I noticed that the text boxes for the actual chart doesn't seem to be working correctly. They are just clustered so I was wondering is there any way for me to move the labels into the middle where the white circle is and have the matching colour beside it or not? crimeTypes = dict(crimeData["Crime type"].value_counts()) crimeType = [] totalAmount = [] numberOfCrimes = 14 for key in sorted(crimeTypes, key=crimeTypes.get, reverse=True): crimeType.append(key)

Dynamically adding a vertical line to matplotlib plot

可紊 提交于 2021-02-16 08:56:45
问题 I'm trying to add vertical lines to a matplotlib plot dynmically when a user clicks on a particular point. import matplotlib.pyplot as plt import matplotlib.dates as mdate class PointPicker(object): def __init__(self,dates,values): self.fig = plt.figure() self.ax = self.fig.add_subplot(111) self.lines2d, = self.ax.plot_date(dates, values, linestyle='-',picker=5) self.fig.canvas.mpl_connect('pick_event', self.onpick) self.fig.canvas.mpl_connect('key_press_event', self.onpress) def onpress(self

Dynamically adding a vertical line to matplotlib plot

青春壹個敷衍的年華 提交于 2021-02-16 08:56:34
问题 I'm trying to add vertical lines to a matplotlib plot dynmically when a user clicks on a particular point. import matplotlib.pyplot as plt import matplotlib.dates as mdate class PointPicker(object): def __init__(self,dates,values): self.fig = plt.figure() self.ax = self.fig.add_subplot(111) self.lines2d, = self.ax.plot_date(dates, values, linestyle='-',picker=5) self.fig.canvas.mpl_connect('pick_event', self.onpick) self.fig.canvas.mpl_connect('key_press_event', self.onpress) def onpress(self

Python: Creating bar plot from pivot table pandas data frame

心不动则不痛 提交于 2021-02-16 05:31:09
问题 I'm new to python and was wondering how to create a barplot on this data I created using pivot table function. #Create a pivot table for handicaps count calculation for no-show people based on their gender pv = pd.pivot_table(df_main, values=['hipertension','diabetes','alcoholism'], columns='status',index='gender',aggfunc=np.sum) #Reshape the pivot table for easier calculation data_pv = pv.unstack().unstack('status').reset_index().rename(columns={'level_0':'category','No-Show':'no_show',

How to show an AxesSubplot in Python?

妖精的绣舞 提交于 2021-02-15 09:53:43
问题 I have an object fig2 that is a class mathplotlib.axes.axessubplot, but when I try to execute fig2.show(), python says axessubplot object has no attribute show. How can I show AxesSubplot? 回答1: You should call matplotlib.pyplot.show() , which is a method that displays all the figures. If you have imported as plt , then: import matplotlib.pyplot as plt # create fig1 (of type plt.figure) # create fig2 plt.show() # will display fig1 and fig2 in different windows 回答2: Alternatively, you could

How to show an AxesSubplot in Python?

此生再无相见时 提交于 2021-02-15 09:49:22
问题 I have an object fig2 that is a class mathplotlib.axes.axessubplot, but when I try to execute fig2.show(), python says axessubplot object has no attribute show. How can I show AxesSubplot? 回答1: You should call matplotlib.pyplot.show() , which is a method that displays all the figures. If you have imported as plt , then: import matplotlib.pyplot as plt # create fig1 (of type plt.figure) # create fig2 plt.show() # will display fig1 and fig2 in different windows 回答2: Alternatively, you could

Plotting graph using scipy.optimize.curve_fit

↘锁芯ラ 提交于 2021-02-15 07:49:10
问题 I am having trouble in understanding the optimize.curve_fit function. My fitting function is a power law. But I don't know exactly what should be the second value in the plot command? First we have to call function ff(L,v) it will return us fitting line but we are not calling this function. How this command is working I want to know that. x=Ls y=Tc #fitting function def ff(L,v): return L**(-1/v) pfit,perr=optimize.curve_fit(ff,x,y) plt.plot(x,...) 回答1: The plot command plots x vs y values, so

Plotting graph using scipy.optimize.curve_fit

我与影子孤独终老i 提交于 2021-02-15 07:47:01
问题 I am having trouble in understanding the optimize.curve_fit function. My fitting function is a power law. But I don't know exactly what should be the second value in the plot command? First we have to call function ff(L,v) it will return us fitting line but we are not calling this function. How this command is working I want to know that. x=Ls y=Tc #fitting function def ff(L,v): return L**(-1/v) pfit,perr=optimize.curve_fit(ff,x,y) plt.plot(x,...) 回答1: The plot command plots x vs y values, so