How can I remove the top and right axis in matplotlib?

This is the suggested Matplotlib 3 solution from the official website HERE: import numpy as np import matplotlib.pyplot as plt x = np.linspace(0, 2*np.pi, 100) y = np.sin(x) ax = plt.subplot(111) ax.plot(x, y) # Hide the right and top spines ax.spines.right.set_visible(False) ax.spines.top.set_visible(False) # Only show ticks on the left and bottom spines ax.yaxis.set_ticks_position(‘left’) ax.xaxis.set_ticks_position(‘bottom’) plt.show()

Plotting time in Python with Matplotlib

Update: This answer is outdated since matplotlib version 3.5. The plot function now handles datetime data directly. See https://matplotlib.org/3.5.1/api/_as_gen/matplotlib.pyplot.plot_date.html The use of plot_date is discouraged. This method exists for historic reasons and may be deprecated in the future. datetime-like data should directly be plotted using plot. If you need to plot plain numeric data as … Read more

How to update a plot in matplotlib

You essentially have two options: Do exactly what you’re currently doing, but call graph1.clear() and graph2.clear() before replotting the data. This is the slowest, but most simplest and most robust option. Instead of replotting, you can just update the data of the plot objects. You’ll need to make some changes in your code, but this … Read more

What is the difference between pylab and pyplot? [duplicate]

This wording is no longer in the documentation. Use of the pylab import is now discouraged and the OO interface is recommended for most non-interactive usage. From the documentation, the emphasis is mine: Matplotlib is the whole package; pylab is a module in matplotlib that gets installed alongside matplotlib; and matplotlib.pyplot is a module in … Read more

How to add a title to a Seaborn boxplot

A Seaborn box plot returns a Matplotlib axes instance. Unlike pyplot itself, which has a method plt.title(), the corresponding argument for an axes is ax.set_title(). Therefore you need to call sns.boxplot(‘Day’, ‘Count’, data=gg).set_title(‘lalala’) A complete example would be: import seaborn as sns import matplotlib.pyplot as plt tips = sns.load_dataset(“tips”) sns.boxplot(x=tips[“total_bill”]).set_title(“LaLaLa”) plt.show() Of course you could … Read more

Format y axis as percent

This is a few months late, but I have created PR#6251 with matplotlib to add a new PercentFormatter class. With this class you just need one line to reformat your axis (two if you count the import of matplotlib.ticker): import … import matplotlib.ticker as mtick ax = df[‘myvar’].plot(kind=’bar’) ax.yaxis.set_major_formatter(mtick.PercentFormatter()) PercentFormatter() accepts three arguments, xmax, decimals, … Read more

Setting different color for each series in scatter plot on matplotlib

I don’t know what you mean by ‘manually’. You can choose a colourmap and make a colour array easily enough: import numpy as np import matplotlib.pyplot as plt import matplotlib.cm as cm x = np.arange(10) ys = [i+x+(i*x)**2 for i in range(10)] colors = cm.rainbow(np.linspace(0, 1, len(ys))) for y, c in zip(ys, colors): plt.scatter(x, y, … Read more

How to plot multiple dataframes in subplots

You can manually create the subplots with matplotlib, and then plot the dataframes on a specific subplot using the ax keyword. For example for 4 subplots (2×2): import matplotlib.pyplot as plt fig, axes = plt.subplots(nrows=2, ncols=2) df1.plot(ax=axes[0,0]) df2.plot(ax=axes[0,1]) … Here axes is an array which holds the different subplot axes, and you can access one … Read more