matplotlib

Set Xticks frequency to dataframe index

给你一囗甜甜゛ 提交于 2021-02-08 10:19:00
问题 I currently have a dataframe that has as an index the years from 1990 to 2014 (25 rows). I want my plot to have the X axis with all the years showing. I'm using add_subplot as I plan to have 4 plots in this figure (all of them with the same X axis). To create the dataframe: import pandas as pd import numpy as np index = np.arange(1990,2015,1) columns = ['Total Population','Urban Population'] pop_plot = pd.DataFrame(index=index, columns=columns) pop_plot = df_.fillna(0) pop_plot['Total

How to set fixed size for 'basemap' subplot when iterating through rows?

女生的网名这么多〃 提交于 2021-02-08 10:14:42
问题 Please forgive me as this is my first go at a Python 'Project'. A quick overview: I am trying to produce maps (MatPlotLib figures) by iterating through a GeoPandas dataframe of a GeoJSON file containing the boundaries of active subdivision phases in order to show the progress of construction of the individual lots in each subdivision phase. We normally did this manually in GIS, but I figured I'd take a stab at automating some, or all, of the process. I am also attempting to do this without

Matplotlib: how to remove contour's clabel

狂风中的少年 提交于 2021-02-08 09:24:12
问题 As we know that we can remove the collections of contour/contourf. But how can I remove the contour's clabel? fig = plt.figure() ax = fig.add_subplots(111) for ivalue in range(10): values = alldata [ivalue,:,:] cs = plt.contour(x,y,vakues) cb = plt.clabel(cs, cs.levels) # now remove cs for c in cs.collections: c.remove() # but how can I remove cb? plt.savefig('%s.png'%ivalue) The clabel of first png still exists in second png. So i want to remove clabel meanwhile. 回答1: You can do the exact

How to remove the previous drawing in matplotlib, Python?

为君一笑 提交于 2021-02-08 08:30:31
问题 I have run 3 Python scripts and each of them generated one curve in the plot. Each curve is made up of hundreds of small line segments. Thus, each curve is drawn by a series of plot() instead of one. But all these plot() share the same parameters (e.g. the color, style of one curve is consistent). Thus, I think it is still possible to easily remove all the segments drawn by particular one script. I find that the curve generated by the most-recently-run script is erroneous. Therefore, I wish

How to remove the previous drawing in matplotlib, Python?

こ雲淡風輕ζ 提交于 2021-02-08 08:30:03
问题 I have run 3 Python scripts and each of them generated one curve in the plot. Each curve is made up of hundreds of small line segments. Thus, each curve is drawn by a series of plot() instead of one. But all these plot() share the same parameters (e.g. the color, style of one curve is consistent). Thus, I think it is still possible to easily remove all the segments drawn by particular one script. I find that the curve generated by the most-recently-run script is erroneous. Therefore, I wish

Change 3D background to black in matplotlib

萝らか妹 提交于 2021-02-08 08:22:21
问题 I'm having trouble changing the background of my 3d graph to black. This is my current code. When I do set facecolor to black, it changes the inside of the graph to be grey, which is not what I want. fig = plt.figure() fig.set_size_inches(10,10) ax = plt.axes(projection='3d') ax.grid(False) ax.xaxis.pane.set_edgecolor('b') ax.yaxis.pane.set_edgecolor('b') ax.zaxis.pane.set_edgecolor('b') # plt.gca().patch.set_facecolor('white') # plt.axis('On') fig.patch.set_facecolor('black') ax.scatter(xs =

plotting sparce time with matplotlib

会有一股神秘感。 提交于 2021-02-08 08:21:46
问题 I want to plot a trading timeseries, e.g. close of 5 min bars. The markets are closed over night. So I have two queries: How to plot time in MatPlotLib (as well as date). E.g. so I need to implement a new axis or new hourLocators etc. How to remove overnight gaps from my plot. I.e. I want the last bar on Monday evening to be visually contiguous with the first bar of Tuesday morning. (Multiple plots won't work here as I need to display several days and pan the view.) 回答1: Look at this example.

Merge colormaps in matplotlib

偶尔善良 提交于 2021-02-08 08:14:21
问题 I want to merge two colormaps for an imshow plot. I want to use 'RdBu' for the range -0.4 to 0.4, then from 0.4 to the maximum value (say 1.5) I want to use a gradient from the same blue to another color (say green for example). How can I do that? This is how far I got so far: import numpy as np import matplotlib.pyplot as plt import matplotlib.colors as colors from matplotlib.mlab import bivariate_normal N = 100 ''' Custom Norm: An example with a customized normalization. This one uses the

Merge colormaps in matplotlib

▼魔方 西西 提交于 2021-02-08 08:13:27
问题 I want to merge two colormaps for an imshow plot. I want to use 'RdBu' for the range -0.4 to 0.4, then from 0.4 to the maximum value (say 1.5) I want to use a gradient from the same blue to another color (say green for example). How can I do that? This is how far I got so far: import numpy as np import matplotlib.pyplot as plt import matplotlib.colors as colors from matplotlib.mlab import bivariate_normal N = 100 ''' Custom Norm: An example with a customized normalization. This one uses the

How to fit non-linear data's in python

↘锁芯ラ 提交于 2021-02-08 07:38:35
问题 How to fit a non linear data's using scipy.optimize import curve_fit in Python using following 3 methods: Gaussian. Lorentz fit. Langmuir fit. I am just able to link and plot from my data file. from matplotlib import pyplot as plt from matplotlib import style import numpy as np import pylab from scipy.optimize import curve_fit style.use('ggplot') data = np.genfromtxt('D:\csvtrail3.csv', delimiter=',', skiprows=1) x=data[:,0] y=data[:,1] data.fit_lorentzians() plt.plot(x, y) plt.title('Epic