Found 784 Articles for Data Visualization

Matplotlib – How to set xticks and yticks with imshow plot?

Rishikesh Kumar Rishi
Updated on 22-Sep-2021 06:52:04

6K+ Views

To set xticks and yticks with imshow() plot, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Get the current axis.Create a random dataset.Display the data as an image, i.e., on a 2D regular raster.Set x and y ticks using set_xticks() and set_yticks() method.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 ax = plt.gca() data = np.random.rand(6, 6) ax.imshow(data) # Set xticks and yticks ax.set_xticks([1, 2, 3, 4, 5]) ax.set_yticks([1, 2, 3, 4, 5]) ... Read More

Remove white border when using subplot and imshow in Python Matplotlib

Rishikesh Kumar Rishi
Updated on 22-Sep-2021 06:50:19

3K+ Views

To remove white border when using subplot and imshow(), 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.Get the size of the data.Set the figure sizes in inches.Get the axes instance that contains most of the figure element.Turn off the axes.Add axes to the figure.Display the data as an image, i.e., on a 2D regular raster.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 = np.random.randint(0, 50, (50, 50)) sizes ... Read More

How to show tick labels on top of a matplotlib plot?

Rishikesh Kumar Rishi
Updated on 22-Sep-2021 06:49:20

5K+ Views

To show tick labels on top of a matplotlib plot, we can use the set_tick_params() method with labeltop=True.StepsSet the figure size and adjust the padding between and around the subplots.Create a figure and a set of subplots.Show the tick labels at the top of the plot. Use set_tick_parama() with labeltop=True.Hide the tick labels of the bottom axis of plot. Use set_tick_parama() with labeltop=False.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt # Set the figure size plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True # Create subplots fig, ax = plt.subplots(1, 1) # Show the ... Read More

How should I pass a matplotlib object through a function; as Axis, Axes or Figure?

Rishikesh Kumar Rishi
Updated on 22-Sep-2021 06:47:53

1K+ Views

To pass a matplotlib object through a function; as Axis, Axes or figure, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.In plot() method, plot x and y data points at axes ax.In profile() method, create a figure and a set of subplots. Iterate the axes and pass in plot() method to plot the figure.Call the profile() method with 3 rows and 4 columns.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True def plot(ax, ... Read More

How to label bubble chart/scatter plot with column from Pandas dataframe?

Rishikesh Kumar Rishi
Updated on 22-Sep-2021 06:38:49

2K+ Views

To label bubble charts/scatter plot with column from Pandas dataframe, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a data frame, df, of two-dimensional, size-mutable, potentially heterogeneous tabular data.Create a scatter plot with df.Annotate each data point with a text.To display the figure, use show() method.Exampleimport pandas as pd from matplotlib import pyplot as plt # Set the figure size plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True # Create a dataframe df = pd.DataFrame( dict( x=[1, 3, 2, ... Read More

How to plot multi-color line if X-axis is datetime index of Pandas?

Rishikesh Kumar Rishi
Updated on 22-Sep-2021 06:36:52

427 Views

To plot multicolor line if X-axis is datetime index of Pandas, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create d, y and s data points using numpy.Create a figure and a set of subplots.Get xval, p and s data point using numpy.Get the line collection instance with hot colormap and s data points.Set major and minor axes locator and set axes formatter.Autoscale the view limits using the data limits.To display the figure, use show() method.Exampleimport pandas as pd from matplotlib import pyplot as plt, dates as mdates, collections as ... Read More

How to get coordinates from the contour in matplotlib?

Rishikesh Kumar Rishi
Updated on 22-Sep-2021 06:32:44

4K+ Views

To get coordinates from the contour in matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create lists of x, y and m with data points.Use plt.contour(x, y, m) to create a contour plot with x, y and m data points.Get the contour collections instance.Get the path of the collections, and print the vertices or coordinates of the contour.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 x = [1, 2, 3, 4] y = [1, 2, 3, 4] m ... Read More

How to sort bars in increasing order in a bar chart in matplotlib?

Rishikesh Kumar Rishi
Updated on 22-Sep-2021 06:30:28

17K+ Views

To sort bars in increasing order in a bar chart in matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make a data frame, df, of two-dimensional, size-mutable, potentially heterogeneous tabular data.Add a subplot to the current figure.Make a bar plot with the dataframe, df.Add a subplot to the current figure.Make a df_sorted by a column marks.Make a bar plot with df_sorted.To display the figure, use show() method.Exampleimport pandas as pd from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame( ... Read More

How to remove random unwanted space in LaTeX-style maths in matplotlib plot?

Rishikesh Kumar Rishi
Updated on 22-Sep-2021 06:27:50

8K+ Views

LaTeX ignores the spaces you type and uses spacing the way it's done in mathematics texts. You can use the following four commands in case you want a different spacing style\; – thick space\: – medium space\, – a thin space\! – a negative thin spaceTo remove random unwanted space in LaTeX-style maths in matplotlib plot, we can use "\!" which will reduce the extra spacing.Let's take an example and understand how it works. We will have two sub-plots and then we will add a complex mathematical equation (using LaTex) in a textbox in both the sub-plots. However, we will ... Read More

How to get pixel coordinates for Matplotlib-generated scatterplot?

Rishikesh Kumar Rishi
Updated on 22-Sep-2021 06:19:45

1K+ Views

To get pixel coordinates for matplotlib-generated scatterplot, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Initialize a variable "n" to hold the number of sample data.Create a figure and a set of subplots.Make a scatter plot.Get the x and y data points using get_data() method.Get the pixel value of the plot.Get the pixel tranformed data.Get the figure width and height in points or pixelsPrint the x and y pixels value.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"] = ... Read More

Advertisements