Found 1034 Articles for Matplotlib

Transparent error bars without affecting the markers in Matplotlib

Rishikesh Kumar Rishi
Updated on 02-Feb-2022 11:26:04

2K+ Views

To make transparent error bars without affecting markers in matplotlib, we can take the following steps −StepsSet the figure size and adjust the padding between and around the subplots.Make lists x, y and z for data.Initialize a variable error_bar_width=5Plot y versus x as lines and/or markers with attached errorbars.Set the alpha value of bars and caps.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = [1, 3, 5, 7] y = [1, 3, 5, 7] z = [4, 5, 1, 4] error_bar_width = 5 markers, ... Read More

How to set legend marker size and alpha in Matplotlib?

Rishikesh Kumar Rishi
Updated on 02-Feb-2022 11:21:30

6K+ Views

To set legend marker size and alpha in matplotlib, we can take the following steps −StepsSet the figure size and adjust the padding between and around the subplots.Initialize a variable N to store the number of sample data.Plot the x and y data points with marker="*".Place a legend on the figure.Set the marker size and alpha value of the marker.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True N = 10 x = np.random.rand(N) y = np.random.rand(N) line, = plt.plot(x, y, marker='*', markersize=20, markeredgecolor='black', ... Read More

Showing points coordinate in a plot in Python Matplotlib

Rishikesh Kumar Rishi
Updated on 02-Feb-2022 11:17:43

11K+ Views

To show points coordinate in a plot in Python, we can take the following steps −StepsSet the figure size and adjust the padding between and around the subplots.Initilize a variable N and create x and y data points using numpy.Zip the x and y data points; iterate them and place coordinates.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True N = 5 x = np.random.rand(N) y = np.random.rand(N) plt.plot(x, y, 'r*') for xy in zip(x, y):    plt.annotate('(%.2f, %.2f)' % xy, xy=xy) ... Read More

How to unset 'sharex' or 'sharey' from two axes in Matplotlib?

Rishikesh Kumar Rishi
Updated on 02-Feb-2022 11:13:03

533 Views

To inset sharex and sharey from two axes in matplotlib, we can use 'none', i.e., False or 'none'. Each subplot X- or Y-axis will be independent.StepsSet the figure size and adjust the padding between and around the subplots.Initialize two variables rows and cols.Create a figure and a set of subplots.Iterate the axes where rows=2 and cols=4.Plot the random data on the axis.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True rows = 2 cols = 4 fig, axes = plt.subplots(rows, cols, sharex='none', sharey='none', squeeze=False) ... Read More

How to obtain 3D colored surface via Python?

Rishikesh Kumar Rishi
Updated on 02-Feb-2022 10:55:15

264 Views

To obtain 3D colored surface via Python, we can take the following steps −StepsSet the figure size and adjust the padding between and around the subplots.Create x and y data points using numpy.Get 3D data, i.e., z.Create a new figure or activate an existing figure.Get the 3D axes.Create a surface plot.To display the figure, use show() method.Exampleimport numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(-3, 3, 100) y = np.cos(x) x, y = np.meshgrid(x, y) z = x ** 2 + y ** 2 - 2 ... Read More

How to set the xticklabels for date in matplotlib?

Rishikesh Kumar Rishi
Updated on 02-Feb-2022 10:51:20

3K+ Views

To set the xticklabels for date in matplotlib, we can take the following steps −StepsSet the figure size and adjust the padding between and around the subplots.Create two lists of epochs and values.Get a list of dates from epochs.Create a figure and a set of subplots.Plot the date and values using plot() method.Set the xticklabels, get date formatter and set the major formatter.To remove the overlapping for ticklabels, rotate it by 10.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import matplotlib.dates as mdates import time plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True epochs = [1259969793926, 1259969793927, ... Read More

Scatter a 2D numpy array in matplotlib

Rishikesh Kumar Rishi
Updated on 02-Feb-2022 10:47:22

18K+ Views

To scatter a 2D numpy array in matplotlib, we can take the following steps −StepsSet the figure size and adjust the padding between and around the subplots.Create random data of 100×3 dimension.Use the scatter() method to plot 2D numpy array, i.e., data.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt # Set the figure size plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Random data of 100×3 dimension data = np.array(np.random.random((100, 3))) # Scatter plot plt.scatter(data[:, 0], data[:, 1], c=data[:, 2], cmap='hot') # Display the plot plt.show()OutputIt will produce ... Read More

How to avoid overlapping error bars in matplotlib?

Rishikesh Kumar Rishi
Updated on 02-Feb-2022 10:44:17

2K+ Views

To avoid overlapping error bars in matplotlib, we can take the following steps −StepsSet the figure size and adjust the padding between and around the subplots.Create a list of names.Get the data points for y1 and y2, and errors ye1, ye2.Create a figure and a set of subplots.Create a mutable 2D affine transformation, trans1 and trans2.Plot y versus x as lines and/or markers with attached errorbars.To display the figure, use show() method.Exampleimport numpy as np import matplotlib.pyplot as plt from matplotlib.transforms import Affine2D plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = ['Jack', 'James', 'Tom', 'Garry'] y1, ... Read More

How do I remove the Y-axis from a Pylab-generated picture?

Rishikesh Kumar Rishi
Updated on 02-Feb-2022 10:40:17

247 Views

To remove the Y-axis from a Pylab-generated picture, we can get the current axis of the plot and use the set_visible(False) method.StepsSet the figure size and adjust the padding between and around the subplots.Create x and y data points using numpy.Plot the x and y data points using plot() method.Get the current axis of the current figure.Set the visibility to False for the Y-axis.To display the figure, use show() method.Exampleimport numpy as np import pylab # Set the figure size pylab.rcParams["figure.figsize"] = [7.50, 3.50] pylab.rcParams["figure.autolayout"] = True # Random data points x = np.random.rand(10) y = np.random.rand(10) ... Read More

Flushing all current figures in matplotlib

Rishikesh Kumar Rishi
Updated on 02-Feb-2022 10:33:33

466 Views

To flush all current figures in matplotlib, use close('all') method.StepsSet the figure size and adjust the padding between and around the subplots.Create a figure with the title "First Figure".Create another figure with the title "Second Figure".To close all figures, use close('all').To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True plt.figure("First Figure") plt.figure("Second Figure") # plt.close('all') plt.show()OutputNotice that we have commented the line −plt.close('all') Hence, it will display two figures −Uncomment the line plt.close('all') and run the code again. It will flush all the current figures.Read More

Previous 1 ... 4 5 6 7 8 ... 104 Next
Advertisements