Found 784 Articles for Data Visualization

How to use multiple font sizes in one label in Python Matplotlib?

Rishikesh Kumar Rishi
Updated on 04-Jun-2021 06:35:58

743 Views

To use multiple font sizes in one label in Python, we can use fontsize in title() method.StepsSet the figure size and adjust the padding between and around the subplots.Create x and y data points using numpy.Plot x and y using plot() method.Initialize a variable, fontsize.Set the title of the plot using title() method with fontsize in the argument.Turn off the axes.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 x = np.linspace(-5, 5, 100) y = np.cos(x) plt.plot(x, y) fontsize = 20 ... Read More

How to put the Origin at the center of the cos curve in a figure in Python Matplotlib?

Rishikesh Kumar Rishi
Updated on 04-Jun-2021 06:34:30

1K+ Views

To put the Origin at the center of the cos curve in a figure, 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.Set the position of the axes using spines, top, left, right and bottom.Plot x and y data points using plot() method.Set the title of the plot.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 x = np.linspace(-5, 5, 100) y = np.cos(x) ax = plt.gca() ... Read More

How do I specify an arrow-like linestyle in Matplotlib?

Rishikesh Kumar Rishi
Updated on 04-Jun-2021 06:33:07

742 Views

To draw an arrow-like linestyle in matplotlib, we can use quiver() method.StepsSet the figure size and adjust the padding between and around the subplots.Create x and y data points using numpy.Use quiver() method to draw a line.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(-5, 5, 100) y = np.sin(x) plt.quiver(x[:-1], y[:-1], x[1:]-x[:-1], y[1:]-y[:-1], scale_units='xy', angles='xy', scale=1, color='red') plt.show()Output

Plot a vector field over the axes in Python Matplotlib?

Rishikesh Kumar Rishi
Updated on 04-Jun-2021 06:31:57

705 Views

To plot a vector field over the axes in matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make X, Y, T, R, U and V data points using numpy.Add an axes to the current figure and make it the current axes.Plot a 3D field of arrows using quiver() method.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 n = 8 X, Y = np.mgrid[0:n, 0:n] T = np.arctan2(Y - n / 2., X - n/2.) ... Read More

How to plot two Pandas time series on the same plot with legends and secondary Y-axis in Matplotlib?

Rishikesh Kumar Rishi
Updated on 04-Jun-2021 06:30:43

2K+ Views

To plot two Pandas time series on the sameplot with legends and secondary Y-axis, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a one-dimensional ndarray with axis labels (including time series).Make a dataframe with some column list.Plot columns A and B using dataframe plot() method.Return the handles and labels for the legend using get_legend_handles_labels() method.Place a legend on the figure using legend() method.To display the figure, use show() method.Exampleimport pandas as pd from matplotlib import pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = ... Read More

How does Python's Matplotlib.pyplot.quiver exactly work?

Rishikesh Kumar Rishi
Updated on 04-Jun-2021 06:29:09

168 Views

To work with quiver, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create vector cordinates using numpy array.Get x, y, u and v data points.Create a new figure or activate an existing figure using figure() method.Get the current axis using gca() method.Set x and y limit of the axes.To redraw the current figure, use draw() method.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 soa = np.array([[0, 0, 3, 2], [0, 0, 4, 5], [0, 0, ... Read More

How to repress scientific notation in factorplot Y-axis in Seaborn / Matplotlib?

Rishikesh Kumar Rishi
Updated on 04-Jun-2021 06:27:44

5K+ Views

To repress scientific notation in factorplot Y-axis in Seaborn/Matplotlib, we can use style="plain" in ticklabel_format()method.StepsSet the figure size and adjust the padding between and around the subplots.Make a dataframe with keys, col1 and col2.The factorplot() has been renamed to catplot().To repress the scientific notation, use style="plain" in ticklabel_format() method.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt import pandas as pd import seaborn as sns plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame({"col1": [1, 3, 5, 7, 1], "col2": [1, 5, 7, 9, 1]}) sns.catplot(y="col1", x="col2", kind='bar', data=df, label="Total", height=3.5) plt.ticklabel_format(style='plain', ... Read More

How to make axes transparent in Matplotlib?

Rishikesh Kumar Rishi
Updated on 04-Jun-2021 06:26:21

3K+ Views

To make axes transparent in matplotlib, we can take the following steps, Set the figure size and adjust the padding between and around the subplots.Create a new figure or activate an existing figure using figure() method.Add an '~.axes.Axes' to the figure as part of a subplot arrangement.Set face color of the current axes.Add an axes to the figure.Create t and s data using numpy.Plot t and s data points using plot() method on axis 2 (from step 5).To make the axis transparent, use set_alpha() method and keep alpha value minimum.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import ... Read More

How to name different lines in the same plot of Matplotlib?

Rishikesh Kumar Rishi
Updated on 04-Jun-2021 06:25:14

1K+ Views

To name different lines in the same plot of matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make two lists of data points.Plot point1 and point2 using plot() method.Place a legend on the figure.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 points1 = [2, 4, 1, 5, 1] points2 = [3, 2, 0, 4, 3] plt.plot(points1, 'g--', label="plot A") plt.plot(points2, 'r-o', label="plot A") plt.legend() plt.show()Output

Drawing circles on an image with Matplotlib and NumPy

Rishikesh Kumar Rishi
Updated on 04-Jun-2021 06:24:09

2K+ Views

To draw a circle on an image with matplotlib and numpy, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Read an image from a file into an array.Create x and y data points using numpy.Create a figure and a set of subplots using subplots() method.Display data as an image, i.e., on a 2D regular raster using imshow() method.Turn off the axes.Add patches on the current axes.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import numpy as np from matplotlib.patches import Circle plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = ... Read More

Advertisements