Matplotlib Articles

Page 33 of 91

How to plot arbitrary markers on a Pandas data series using Matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 25-Mar-2026 489 Views

To plot arbitrary markers on a Pandas data series, we can use pyplot.plot() with custom markers and styling options. This is useful for visualizing time series data or any indexed data with distinctive markers. Steps Set the figure size and adjust the padding between and around the subplots Create a Pandas data series with axis labels (including timeseries) Plot the series using plot() method with custom markers and line styles Use tick_params() method to rotate overlapping labels for better readability Display the figure using show() method Example Here's how to create a time series ...

Read More

How to change the range of the X-axis and Y-axis in Matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 25-Mar-2026 80K+ Views

To change the range of X and Y axes in Matplotlib, we can use xlim() and ylim() methods. These methods allow you to set custom minimum and maximum values for both axes. Using xlim() and ylim() Methods The xlim() and ylim() methods accept two parameters: the minimum and maximum values for the respective axis ? import numpy as np import matplotlib.pyplot as plt # Set the figure size and adjust the padding between and around the subplots plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Create x and y data points using numpy x ...

Read More

How to view all colormaps available in Matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 25-Mar-2026 240 Views

Matplotlib provides numerous built-in colormaps for visualizing data. You can view all available colormaps programmatically or create animations to cycle through them. Listing All Available Colormaps The simplest way to see all colormap names is using plt.colormaps() ? import matplotlib.pyplot as plt # Get all colormap names colormaps = plt.colormaps() print(f"Total colormaps available: {len(colormaps)}") print("First 10 colormaps:", colormaps[:10]) Total colormaps available: 166 First 10 colormaps: ['Accent', 'Accent_r', 'Blues', 'Blues_r', 'BrBG', 'BrBG_r', 'BuGn', 'BuGn_r', 'BuPu', 'BuPu_r'] Displaying Colormap Categories Colormaps are organized into categories like sequential, diverging, and qualitative ? ...

Read More

How to customize X-axis ticks in Matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 25-Mar-2026 4K+ Views

To customize X-axis ticks in Matplotlib, you can modify their appearance including length, width, color, and direction using the tick_params() method. Basic X-axis Tick Customization Let's start with a simple bar chart and customize the X-axis ticks ? import numpy as np import matplotlib.pyplot as plt # Set figure size plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Sample data height = [3, 12, 5, 18, 45] bars = ('A', 'B', 'C', 'D', 'E') y_pos = np.arange(len(bars)) # Create bar plot plt.bar(y_pos, height, color='yellow') # Customize X-axis ticks plt.tick_params(axis='x', colors='red', direction='out', length=7, ...

Read More

How to remove grid lines from an image in Python Matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 25-Mar-2026 7K+ Views

To remove grid lines from an image in Python Matplotlib, you need to explicitly disable the grid using grid(False). By default, Matplotlib may show grid lines over images, which can interfere with image visualization. Steps to Remove Grid Lines Set the figure size and adjust the padding between and around the subplots Load an image from a file Convert the image from one color space to another if needed To remove grid lines, use ax.grid(False) or plt.grid(False) Display the data as an image using imshow() Display the figure using show() method Example Here's how ...

Read More

How to save a plot in Seaborn with Python (Matplotlib)?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 25-Mar-2026 4K+ Views

To save a plot in Seaborn, we can use the savefig() method from Matplotlib. Since Seaborn is built on top of Matplotlib, we can save any Seaborn plot using this approach. Basic Syntax import matplotlib.pyplot as plt # Create your Seaborn plot # Then save it plt.savefig('filename.png') Example: Saving a Pairplot Let's create a pairplot and save it to a file − import seaborn as sns import pandas as pd import numpy as np import matplotlib.pyplot as plt # Set figure parameters plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True ...

Read More

Create a legend with Pandas and Matplotlib.pyplot

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 25-Mar-2026 1K+ Views

To create a legend with Pandas and matplotlib.pyplot, we can plot DataFrame data and enable the legend parameter. The legend helps identify different data series in the plot. Steps to Create a Legend Set the figure size and adjust the padding between and around the subplots. Create a DataFrame with multiple columns for plotting. Plot the DataFrame using plot() method with legend=True. Display the figure using show() method. Example Let's create a bar chart with a legend showing two data series ? import pandas as pd from matplotlib import pyplot as plt ...

Read More

Frequency plot in Python/Pandas DataFrame using Matplotlib

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 25-Mar-2026 16K+ Views

A frequency plot visualizes how often each value appears in a dataset. In Python, you can create frequency plots from Pandas DataFrames using Matplotlib's plotting capabilities. Basic Frequency Plot Here's how to create a simple frequency plot using value_counts() and Matplotlib ? import pandas as pd import matplotlib.pyplot as plt # Configure plot settings plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Create a DataFrame df = pd.DataFrame({'numbers': [2, 4, 1, 4, 3, 2, 1, 3, 2, 4]}) # Create frequency plot fig, ax = plt.subplots() df['numbers'].value_counts().plot(ax=ax, kind='bar', xlabel='numbers', ylabel='frequency') plt.show() ...

Read More

How do I print a Celsius symbol with Matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 25-Mar-2026 1K+ Views

To print a Celsius symbol (°C) with Matplotlib, you can use LaTeX mathematical notation within text labels. The degree symbol is rendered using ^\circ in math mode. Basic Example with Celsius Symbol Here's how to display the Celsius symbol in axis labels ? import matplotlib.pyplot as plt import numpy as np # Set figure size plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Generate sample temperature data N = 10 temperature = np.random.rand(N) * 30 # Temperature in Celsius pressure = np.random.rand(N) * 100 # Pressure values # Create ...

Read More

Automated legend creation in Matplotlib

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 25-Mar-2026 990 Views

Matplotlib can automatically create legends for scatter plots using the legend_elements() method. This is particularly useful when plotting data with multiple categories or varying sizes. Basic Automated Legend The legend_elements() method extracts legend information from scatter plots ? import matplotlib.pyplot as plt import numpy as np # Set figure size plt.figure(figsize=(8, 6)) # Generate sample data N = 30 x = np.random.rand(N) y = np.random.rand(N) colors = np.random.randint(1, 4, size=N) # 3 categories # Create scatter plot scatter = plt.scatter(x, y, c=colors, s=100, cmap='viridis') # Automatically create legend for colors legend ...

Read More
Showing 321–330 of 902 articles
« Prev 1 31 32 33 34 35 91 Next »
Advertisements