matplotlib

Arrange two plots horizontally

谁都会走 提交于 2021-02-05 08:09:49
问题 As an exercise, I'm reproducing a plot from The Economist with matplotlib So far, I can generate a random data and produce two plots independently. I'm struggling now with putting them next to each other horizontally. import pandas as pd import matplotlib.pyplot as plt import numpy as np %matplotlib inline df1 = pd.DataFrame({"broadcast": np.random.randint(110, 150,size=8), "cable": np.random.randint(100, 250, size=8), "streaming" : np.random.randint(10, 50, size=8)}, index=pd.Series(np

Arrange two plots horizontally

空扰寡人 提交于 2021-02-05 08:07:28
问题 As an exercise, I'm reproducing a plot from The Economist with matplotlib So far, I can generate a random data and produce two plots independently. I'm struggling now with putting them next to each other horizontally. import pandas as pd import matplotlib.pyplot as plt import numpy as np %matplotlib inline df1 = pd.DataFrame({"broadcast": np.random.randint(110, 150,size=8), "cable": np.random.randint(100, 250, size=8), "streaming" : np.random.randint(10, 50, size=8)}, index=pd.Series(np

Animating a pcolormesh with contours with maltpoltlib

半世苍凉 提交于 2021-02-05 07:57:10
问题 I am working on something : I need to vizualize the progress of, let us say heat, in time and on a surface. I'm having some troubles animating a pcolormesh with contours : the contour is indeed animated, but the pcolormesh is not ; I only get the first one that is never replaced. My code is quite like this : #x, y and z_temp are previously extracted from an Excel file z=np.zeros(time,y,x) for t in range(time): for m in range(len(y)): for n in range(len(x)): z[t][m][n] = z_temp[t] x,y=np

Is it possible to align x-axis ticks with corresponding bars in a matplotlib histogram?

北战南征 提交于 2021-02-05 07:51:33
问题 While plotting time-series date, i'm trying to plot the number of data points per hour: fig, ax = plt.subplots() ax.hist(x = df.index.hour, bins = 24, # draw one bar per hour align = 'mid' # this is where i need help rwidth = 0.6, # adding a bit of space between each bar ) I want one bar per hour, each hour labeled, so we set: ax.set_xticks(ticks = np.arange(0, 24)) ax.set_xticklabels(labels = [str(x) for x in np.arange(0, 24)]) The x-axis ticks are shown and labelled correctly, yet the bars

Is it possible to align x-axis ticks with corresponding bars in a matplotlib histogram?

独自空忆成欢 提交于 2021-02-05 07:51:14
问题 While plotting time-series date, i'm trying to plot the number of data points per hour: fig, ax = plt.subplots() ax.hist(x = df.index.hour, bins = 24, # draw one bar per hour align = 'mid' # this is where i need help rwidth = 0.6, # adding a bit of space between each bar ) I want one bar per hour, each hour labeled, so we set: ax.set_xticks(ticks = np.arange(0, 24)) ax.set_xticklabels(labels = [str(x) for x in np.arange(0, 24)]) The x-axis ticks are shown and labelled correctly, yet the bars

Detect when matplotlib tick labels overlap

冷暖自知 提交于 2021-02-05 07:09:22
问题 I have a matplotlib bar chart generated by pandas, like this: index = ["Label 1", "Label 2", "Lorem ipsum dolor sit amet", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis ac vehicula leo, vitae sodales orci."] df = pd.DataFrame([1, 2, 3, 4], columns=["Value"], index=index) df.plot(kind="bar", rot=0) As you can see, with 0 rotation, the xtick labels overlap. How can I detect when two labels overlap, and rotate just those two labels to 90 degrees? 回答1: There is no easy way to

Detect when matplotlib tick labels overlap

。_饼干妹妹 提交于 2021-02-05 07:08:30
问题 I have a matplotlib bar chart generated by pandas, like this: index = ["Label 1", "Label 2", "Lorem ipsum dolor sit amet", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis ac vehicula leo, vitae sodales orci."] df = pd.DataFrame([1, 2, 3, 4], columns=["Value"], index=index) df.plot(kind="bar", rot=0) As you can see, with 0 rotation, the xtick labels overlap. How can I detect when two labels overlap, and rotate just those two labels to 90 degrees? 回答1: There is no easy way to

Detect when matplotlib tick labels overlap

一世执手 提交于 2021-02-05 07:06:30
问题 I have a matplotlib bar chart generated by pandas, like this: index = ["Label 1", "Label 2", "Lorem ipsum dolor sit amet", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis ac vehicula leo, vitae sodales orci."] df = pd.DataFrame([1, 2, 3, 4], columns=["Value"], index=index) df.plot(kind="bar", rot=0) As you can see, with 0 rotation, the xtick labels overlap. How can I detect when two labels overlap, and rotate just those two labels to 90 degrees? 回答1: There is no easy way to

set y-axis in millions [duplicate]

荒凉一梦 提交于 2021-02-05 06:03:53
问题 This question already has answers here : How to format seaborn/matplotlib axis tick labels from number to thousands or Millions? (125,436 to 125.4K) (4 answers) Closed 10 months ago . I have a problem with this plot: [![enter image description here][1]][1] The y-axis is in unit but I need them to be in millions as such: [![enter image description here][2]][2] Do you know a method to achieve this? Thanks in advance. 回答1: You can use a custom FuncFormatter like this: from matplotlib.ticker

Matplotlib dates YearLocator with odd intervals

≡放荡痞女 提交于 2021-02-05 05:59:45
问题 Right now I have a working bit of code that formats to my specification when my time series begin at the start of a decade (i.e. 1990, 2000, 2010,etc.), but I don't know how to adapt my code to have the correct formatting when my time series begins at a year that isn't even (i.e. 1993). import pandas as pd import matplotlib.pyplot as plt from matplotlib import dates def format_xaxis(fig): years = dates.YearLocator(10,month=1,day=1) years1=dates.YearLocator(2,month=1,day=1) dfmt = dates