What do you want to save?
Add Code snippet
New code examples
-
Python 2022-03-02 12:20:01
significant figures on axes plot matplotlib
import matplotlib.pyplot as plt import numpy as np from matplotlib.ticker import FormatStrFormatter fig, ax = plt.subplots() ax.yaxis.set_major_formatter(FormatStrFormatter('%g')) ax.yaxis.set_ticks(np.arange(-2, 2, 0.25)) x = np.arange(-1, 1, 0.1) plt... Add solution -
Python 2022-02-15 20:00:08
how to plot side by side bar horizontal bar graph in python
import pandas import matplotlib.pyplot as plt import numpy as np df = pandas.DataFrame(dict(graph=['Item one', 'Item two', 'Item three'], n=[3, 5, 2], m=[6, 1, 3])) ind = np.arange(len(df)) width = 0.4 fig, ax = plt.subplots... Add solution -
Python 2022-01-23 08:15:31
pyplot rectangle over image
import matplotlib.pyplot as plt import matplotlib.patches as patches from PIL import Image im = Image.open('stinkbug.png') # Create figure and axes fig, ax = plt.subplots() # Display the image ax.imshow(im) # Create a Rectangle patch rect = patches.Re... Add solution -
Python 2021-11-15 14:14:28
this figure includes axes that are not compatible with tight_layout, so results might be incorrect
fig, ax = plt.subplots() fig.set_tight_layout(False) X = np.linspace(-np.pi, np.pi, 256,endpoint=True) C,S = np.cos(X), np.sin(X) ax.plot(X,C) ax.plot(X,S) plt.show() Add solution -
Python 2021-10-24 10:07:08
change xlabel python
import matplotlib.pyplot as plt fig, ax = plt.subplots() # We need to draw the canvas, otherwise the labels won't be positioned and # won't have values yet. fig.canvas.draw() labels = [item.get_text() for item in ax.get_xticklabels()] labels[1] = 'Tes... Add solution -
Python 2021-10-20 14:20:10
python convert ylabel to currency
import numpy as np import matplotlib.pyplot as plt import matplotlib.ticker as ticker # Fixing random state for reproducibility np.random.seed(19680801) fig, ax = plt.subplots() ax.plot(100*np.random.rand(20)) formatter = ticker.FormatStrFormatter('$%1... Add solution -
Other 2021-10-20 08:32:13
sklearn random forest feature importance
import pandas as pd forest_importances = pd.Series(importances, index=feature_names) fig, ax = plt.subplots() forest_importances.plot.bar(yerr=std, ax=ax) ax.set_title("Feature importances using MDI") ax.set_ylabel("Mean decrease in impuri... Add solution