matplotlib

Python seaborn catplot - How do I change the y-axis scale to percentage

倾然丶 夕夏残阳落幕 提交于 2021-02-07 08:23:22
问题 In the figure the y-axis labels are in decimals from (0 to 1) i.e (0.1, 0.2, 0.4 etc). How can I convert this into a % format (10%, 20%, 40% etc). Just 10, 20, 40 also will do. Thanks, John g = sns.catplot(x="who", y="survived", col="class", ... data=titanic, saturation=.5, ... kind="bar", ci=None, aspect=.6) 回答1: You may use a PercentFormatter on the axes of the grid. import seaborn as sns import matplotlib.pyplot as plt from matplotlib.ticker import PercentFormatter titanic = sns.load

Find holes in a union of rectangles?

眉间皱痕 提交于 2021-02-07 08:22:31
问题 I have a number of random rectangles (black) in and around a unit square (red) and need to extract all the polygonal regions inside the unit square that are not covered by any rectangle. It looks like this can be done with Shapely and I've gotten to the point when I have the union of the rectangles (green) but I'm not sure how to subtract that from the unit square and retrieve a list of polygons. Here is my code to generate the test data: import pylab import random from matplotlib import

Find holes in a union of rectangles?

女生的网名这么多〃 提交于 2021-02-07 08:21:30
问题 I have a number of random rectangles (black) in and around a unit square (red) and need to extract all the polygonal regions inside the unit square that are not covered by any rectangle. It looks like this can be done with Shapely and I've gotten to the point when I have the union of the rectangles (green) but I'm not sure how to subtract that from the unit square and retrieve a list of polygons. Here is my code to generate the test data: import pylab import random from matplotlib import

Python seaborn catplot - How do I change the y-axis scale to percentage

狂风中的少年 提交于 2021-02-07 08:19:54
问题 In the figure the y-axis labels are in decimals from (0 to 1) i.e (0.1, 0.2, 0.4 etc). How can I convert this into a % format (10%, 20%, 40% etc). Just 10, 20, 40 also will do. Thanks, John g = sns.catplot(x="who", y="survived", col="class", ... data=titanic, saturation=.5, ... kind="bar", ci=None, aspect=.6) 回答1: You may use a PercentFormatter on the axes of the grid. import seaborn as sns import matplotlib.pyplot as plt from matplotlib.ticker import PercentFormatter titanic = sns.load

matplotlib imshow fixed aspect and vertical colorbar matching master axis height

ε祈祈猫儿з 提交于 2021-02-07 08:19:48
问题 I need to plot a mesh grid with "temperature map" values, currently I'm using imshow , with a colormap. This is described in the Matplotlib overview, so I modified the example to force custom aspect of the figure: import matplotlib.pyplot as plt from mpl_toolkits.axes_grid1 import make_axes_locatable import numpy as np plt.figure() ax = plt.gca() im = ax.imshow(np.arange(100).reshape((10,10)), aspect=0.5) # create an axes on the right side of ax. The width of cax will be 5% # of ax and the

matplotlib imshow fixed aspect and vertical colorbar matching master axis height

倖福魔咒の 提交于 2021-02-07 08:17:40
问题 I need to plot a mesh grid with "temperature map" values, currently I'm using imshow , with a colormap. This is described in the Matplotlib overview, so I modified the example to force custom aspect of the figure: import matplotlib.pyplot as plt from mpl_toolkits.axes_grid1 import make_axes_locatable import numpy as np plt.figure() ax = plt.gca() im = ax.imshow(np.arange(100).reshape((10,10)), aspect=0.5) # create an axes on the right side of ax. The width of cax will be 5% # of ax and the

Pandas groupby year object plotting it year over year

旧街凉风 提交于 2021-02-07 07:55:05
问题 I want to plot 6 years of 12 month period data on one 12 month axis from Dec - Jan. import pandas as pd import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt df = pd.Series(np.random.randn(72), index=pd.date_range('1/1/2000', periods=72, freq='M')) grouped = df.groupby(df.index.map(lambda x: x.year)) grouped.plot() So I'm getting the breaks in the lines between each year. However, what I want to do is have the year stacked over each other. Any simple and clean ways to do

Pandas groupby year object plotting it year over year

ぃ、小莉子 提交于 2021-02-07 07:53:06
问题 I want to plot 6 years of 12 month period data on one 12 month axis from Dec - Jan. import pandas as pd import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt df = pd.Series(np.random.randn(72), index=pd.date_range('1/1/2000', periods=72, freq='M')) grouped = df.groupby(df.index.map(lambda x: x.year)) grouped.plot() So I'm getting the breaks in the lines between each year. However, what I want to do is have the year stacked over each other. Any simple and clean ways to do

back-to-back histograms in matplotlib

北城余情 提交于 2021-02-07 07:52:23
问题 There is a nice function that draws back to back histograms in Matlab. I need to create a similar graph in matplotlib. Can anyone show a working code example? 回答1: Thanks to the link pointed by Mark Rushakoff, following is what I finally did import numpy as np from matplotlib import pylab as pl dataOne = get_data_one() dataTwo = get_data_two() hN = pl.hist(dataTwo, orientation='horizontal', normed=0, rwidth=0.8, label='ONE') hS = pl.hist(dataOne, bins=hN[1], orientation='horizontal', normed=0

Matplotlib table formatting - change width of row label cells

柔情痞子 提交于 2021-02-07 07:41:37
问题 I have an obvious problem with this table, because the row labels are outside of the figure and I don't know how to fix it. I know I can go into child artists and change things like height and width there, but I already tried it and it didn't work, so maybe you can help me now. Here is the code I'm using for this, hope it isn't too hard to read.... : ind1=np.arange(5) figure() axes([0.2, 0.45, 0.7, 0.45]) ## define different bars l1=bar((ind1-0.45),mean_morphing_cc[0:5],width=0.2,bottom=0