Found 784 Articles for Data Visualization

Aligning table to X-axis using matplotlib Python

Rishikesh Kumar Rishi
Updated on 19-Oct-2021 08:14:27

1K+ Views

To align a table to X-axis using matplotlib, we can take the following stepsStepsSet the figure size and adjust the padding between and around the subplots.Create a list of data for the dataframe.Create a tuple for dataframe's columns.Create a list of rows and values.Initialize a variable value_increment.Create a bar plot with the data points.Put the data into a table.Set y-label, yticks, xticks, and the title of the plot.To display the figure, use Show() method.Exampleimport numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True data = [    [66386, 174296, 75131, 577908, 32015],   ... Read More

How to plot int to datetime on X-axis using Seaborn?

Rishikesh Kumar Rishi
Updated on 19-Oct-2021 08:12:41

3K+ Views

To plot int to datetime on X-axis using Seaborn in matplotlib, we can take the following stepsStepsSet the figure size and adjust the padding between and around the subplots.Create a dataframe, df, of two-dimensional, size-mutable, potentially heterogeneous tabular data, with three columns.Create a countplot with int, i.e., dob on the X-axis.Set int to datetime label on the X-axis.To display the figure, use Show() method.Exampleimport seaborn as sns from matplotlib import pyplot as plt import pandas as pd import numpy as np # Set the figure size plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True # Data frame with 3 ... Read More

How to show numpy 2D array as grayscale image in Jupyter Notebook?

Rishikesh Kumar Rishi
Updated on 09-Oct-2021 08:57:15

4K+ Views

To show a 2D array as a grayscale image in Jupyter Notebook, we can take the following stepsStepsSet the figure size and adjust the padding between and around the subplots.Create a random data using numpy.Display the data as an image, i.e., on a 2D regular raster, with gray colormap.To display the figure, use Show() method.Examplefrom matplotlib import pyplot as plt import numpy as np # Set the figure size plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True # Random data points data = np.random.rand(5, 5) # Plot the data using imshow with gray colormap plt.imshow(data, cmap='gray') # ... Read More

Filling the region between a curve and X-axis in Python using Matplotlib

Rishikesh Kumar Rishi
Updated on 09-Oct-2021 08:55:24

1K+ Views

To fill the region between a curve and X-axis in Python using Matplotlib, we can take the following stepsStepsSet 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.Fill the area between the curve and the X-axis using fill_between() method.To display the figure, use Show() method.Exampleimport matplotlib.pyplot as plt import numpy as np # Set the figure size plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True # Create x and y data points x = np.linspace(-5, 5, 100) y = np.sin(x) ... Read More

How do I use colorbar with hist2d in matplotlib.pyplot?

Rishikesh Kumar Rishi
Updated on 09-Oct-2021 08:53:36

600 Views

To use colorbar with hist2d in matplotlib.pyplot, we can take the following steps.StepsSet the figure size and adjust the padding between and around the subplots.Initialize a variable "N" for the number of sample data.Createx and y data points using numpy.Create a figure and a set of subplots using subplots() method.Make a 2D histogram plot using hist2D().Create a colorbar for the hist2d scalar mappable instance.To display the figure, use Show() method.Examplefrom matplotlib.colors import LogNorm import matplotlib.pyplot as plt import numpy as np # Set the figure size plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True # Number of sample data ... Read More

How to use unicode symbols in matplotlib?

Rishikesh Kumar Rishi
Updated on 09-Oct-2021 08:51:41

1K+ Views

To use unicode symbols in matplotlib, we can take the following steps.StepsSet the figure size and adjust the padding between and around the subplots.Add text to figure, using text() method with unicode symbols. Here we have used the Unicode chararacter (Δ) which has the character code (0394).To display the figure, use Show() method.Exampleimport matplotlib.pyplot as plt # Set the figure size plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True # Unicode symbol plt.text(0.5, 0.5, s=u"\u0394", fontsize=50) # Display the plot plt.show() OutputIt will produce the following output −Now, let's use another Unicode character (\u2734).It will produce the following ... Read More

How to build colorbars without attached plot in matplotlib?

Rishikesh Kumar Rishi
Updated on 19-Oct-2021 08:07:18

110 Views

To build colorbars without attached plot in matplotlib, we can take the following steps.StepsSet the figure size and adjust the padding between and around the subplots.Create a figure and a set of subplots.Adjust the subplot layout parameters.Normalize the quaternion in place. Return the norm of the quaternion.Get the colorbar instance (cb) with base colorbar and horizontal orientation.To display the figure, use Show() method.Exampleimport matplotlib.pyplot as plt import matplotlib as mpl # Set the figure size plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True # Create a figure and a set of subplots fig, ax = plt.subplots() # Adjust ... Read More

How to append a single labeled tick to X-axis using matplotlib?

Rishikesh Kumar Rishi
Updated on 09-Oct-2021 08:47:22

2K+ Views

Tp append a single labeled tick to X-axis using matplotlib, 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.Plot x and y data points using plot() method.Set xticks at a single point.Set the tick label for single tick point.To display the figure, use Show() method.Exampleimport numpy as np import matplotlib.pyplot as plt # Set the figure size plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True # Create x and y data points x = np.linspace(-5, 5, 50) y = np.sin(x) # Plot ... Read More

How to cycle through both colours and linestyles on a matplotlib figure?

Rishikesh Kumar Rishi
Updated on 19-Oct-2021 08:06:20

1K+ Views

To cycle through both colors and linestyles on a matplotlib figure, we can take the following steps.StepsSet the figure size and adjust the padding between and around the subplots.Set the current rcParams, withcolors and linestyle.Plot the data points using plot() method.To display the figure, use Show() method.Exampleimport matplotlib.pyplot as plt from cycler import cycler # Set the figure size plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True # Set the rcParams with color or linestyle plt.rc('axes', prop_cycle=(cycler('color', ['r', 'g', 'b', 'y']) + cycler('linestyle', [':', '-.', '-', '--']))) # Plot the data points plt.plot([0, 5, 2, ... Read More

How to better rasterize a plot without blurring the labels in matplotlib?

Rishikesh Kumar Rishi
Updated on 19-Oct-2021 08:05:33

453 Views

To rasterize a plot in a bettery way without blurring the labels in matplotlib, we can take the following steps.StepsSet the figure size and adjust the padding between and around the subplots.Create a figure and a set of subplots.Axis 0 – Fill the area between the curve with alpha and rasterized=False.Add text to the axes.Axis 1 – Fill the area between the curve with alpha and rasterized=True.Add text to the axes.Axes 2 and 3 – Fill the area between the curve without alpha and rasterized=True and False, respectively.Add text to the axes.To display the figure, use Show() method.Exampleimport matplotlib.pyplot as ... Read More

Advertisements