Found 784 Articles for Data Visualization

Plotting grids across the subplots in Python Matplotlib

Rishikesh Kumar Rishi
Updated on 09-Jun-2021 12:41:00

6K+ Views

To plot grids across the subplots in Python Matplotlib, we can create multiple subplots and set the spine visibility false out of multiple axes.StepsSet the figure size and adjust the padding between and around the subplots.Create a figure and a set of subplots using subplots() method.Add a subplot to the current figure and set its spine visibility as false.Turn off the a☓3 labels.Share the X-axis accordingly.Configure the grid lines for a☓1, a☓2 and a☓3.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig, (ax1, ax2) = plt.subplots(nrows=2) ax3 = fig.add_subplot(111, zorder=-1) ... Read More

How to set different opacity of edgecolor and facecolor of a patch in Matplotlib?

Rishikesh Kumar Rishi
Updated on 09-Jun-2021 12:28:30

4K+ Views

To set different opacity of edge and face color, we can use a color tuple and the 4th index of the tuple could set the opacity value of the colors.StepsSet the figure size and adjust the padding between and around the subplots.Create a figure and a set of subplots using subplots() method.Set different values for edge and face color opacity.Add a rectangel patch using add_patch() method.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt, patches plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True figure, ax = plt.subplots() edge_color_opacity = 1 # 0Read More

How do I plot a spectrogram the same way that pylab's specgram() does? (Matplotlib)

Rishikesh Kumar Rishi
Updated on 09-Jun-2021 12:22:41

349 Views

To plot a spectrogram the same way that pylab's specgram() does, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create t, s1, s2, nse, x, NEFT and Fs data points using numpy.Create a new figure or activate an existing figure using subplots() method with nrows=2.Plot t and x data points using plot() method.Lay out a grid in current line style.Set the X-axis margins.Plot a spectrogram using specgram() method.Lay out a grid in current line style with dotted linestyle and some other properties.To display the figure, use show() method.Exampleimport matplotlib.pyplot as ... Read More

Adding a line to a scatter plot using Python's Matplotlib

Rishikesh Kumar Rishi
Updated on 09-Jun-2021 12:11:11

15K+ Views

To add a line to a scatter plot using Python's Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Initialize a variable, n, for number of data points.Plot x and y data points using scatter() method.Plot a line using plot() method.Limt the X-axis using xlim() method.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True n = 100 x = np.random.rand(n) y = np.random.rand(n) plt.scatter(x, y, c=x) plt.plot([0.1, 0.4, 0.3, 0.2]) plt.xlim(0, 1) ... Read More

How to disable the keyboard shortcuts in Matplotlib?

Rishikesh Kumar Rishi
Updated on 09-Jun-2021 12:10:54

447 Views

To disable the keyboard shortcuts in Matplotlib, we can use remove('s') method.StepsSet the figure size and adjust the padding between and around the subplots.To disable the shortcut "s" to save the figure, use remove("s") method.Initialize a variable n for number of data points.Create x and y data points using numpyPlot x and y data points using plot() method.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True plt.rcParams['keymap.save'].remove('s') n = 10 x = np.random.rand(n) y = np.random.rand(n) plt.plot(x, y) plt.show()OutputRead More

How to plot categorical variables in Matplotlib?

Rishikesh Kumar Rishi
Updated on 09-Jun-2021 12:16:54

4K+ Views

To plot categorical variables in Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a dictionary with some details.Extract the keys and values from the dictionary (Step 2).Create a figure and a set of subplots.Plot bar, scatter and plot with names and values data.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True data = {'apple': 10, 'orange': 15, 'lemon': 5} names = list(data.keys()) values = list(data.values()) fig, axs = plt.subplots(1, 3) axs[0].bar(names, values) axs[1].scatter(names, values) axs[2].plot(names, values) ... Read More

How do I change the font size of the scale in Matplotlib plots?

Rishikesh Kumar Rishi
Updated on 09-Jun-2021 12:17:35

8K+ Views

To change the font size of the scale in Matplotlib, we can use labelsize in the tick_params() method.StepsSet the figure size and adjust the padding between and around the subplots.Create a figure and a set of subplots.Plot x data points using plot() method.To change the font size of the scale in matplotlib, we can use labelsize in the ticks_params()method.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig, ax = plt.subplots() x = np.random.rand(10) ax.plot(x) ax.tick_params(axis='x', labelsize=20) plt.show()OutputRead More

How to save an array as a grayscale image with Matplotlib/Numpy?

Rishikesh Kumar Rishi
Updated on 09-Jun-2021 12:17:54

3K+ Views

To save an array as a grayscale image with Matplotlib/numpy, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create random data with 5☓5 dimension.Set the colormap to "gray".Plot the data using imshow() method.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True arr = np.random.rand(5, 5) plt.gray() plt.imshow(arr) plt.show()Output

How can I set the location of minor ticks in Matplotlib?

Rishikesh Kumar Rishi
Updated on 09-Jun-2021 12:09:09

6K+ Views

To set the location of the minor ticks in Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create x and y data points using numpy.Create a figure and a set of subplots.Plot x and y data points using plot() method.To locate minor ticks, use set_minor_locator() method.To show the minor ticks, use grid(which='minor').To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import numpy as np from matplotlib.ticker import AutoMinorLocator plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(1, 10, 100) y = np.log(x) fig, ax ... Read More

How to label and change the scale of a Seaborn kdeplot's axes? (Matplotlib)

Rishikesh Kumar Rishi
Updated on 09-Jun-2021 12:08:50

1K+ Views

To label and change the scale of a Seaborn kdeplot's axes, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create random data points using numpy.Plot Kernel Density Estimate (KDE) using kdeplot() method.Set Y-axis tscale and label.To display the figure, use show() method.Exampleimport numpy as np import seaborn as sns from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True data = np.random.randn(10) k = sns.kdeplot(x=data, shade=True) plt.yticks(k.get_yticks(), k.get_yticks()) plt.ylabel('Y', fontsize=7) plt.show()OutputRead More

Advertisements