Found 784 Articles for Data Visualization

How do I print a Celsius symbol with Matplotlib?

Rishikesh Kumar Rishi
Updated on 10-Jun-2021 11:59:08

750 Views

To print Celsius symbol with Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Initialize a variable, N.Create T and P data points using numpy.Plot T and P using plot() method.Set the label for the X-axis.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True N = 10 T = np.random.rand(N) P = np.random.rand(N) plt.plot(T, P) plt.xlabel("$Temperature {^\circ}C$") plt.show()Output

Automated legend creation in Matplotlib

Rishikesh Kumar Rishi
Updated on 10-Jun-2021 11:58:42

719 Views

To automate legend creation in 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 sample data.Create x, y, c and s data using numpy.Create a figure and a set of subplots using subplots() method.Plot x and y data points with different colors and sizes.Place a legend on the axes.Add an artist to the figure.Create legend handles and labels for a PathCollection.Again, place a legend on the axes for sizes.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import numpy as np ... Read More

How to plot a nested pie chart in Matplotlib?

Rishikesh Kumar Rishi
Updated on 10-Jun-2021 11:58:13

1K+ Views

To plot a nested pie chart in Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a figure and a set of subplots.Initialize a variable size, create vals, cmap, outer_colors, inner_colors data using numpy.Use pie() function to make pie charts.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig, ax = plt.subplots() size = 0.3 vals = np.array([[60., 32.], [37., 40.], [29., 10.]]) cmap = plt.get_cmap("tab20c") outer_colors = cmap(np.arange(3)*4) inner_colors = cmap([1, 2, 5, 6, 9, ... Read More

How to set NetworkX edge labels offset in Matplotlib?

Rishikesh Kumar Rishi
Updated on 10-Jun-2021 11:57:42

1K+ Views

To set the networkx edge labels offset, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Initialize a graph with edges, name, or graph attributes.Add multiple nodes.Add all the edges using add_edge_from() method.Position the nodes using Fruchterman-Reingold force-directed algorithm.Draw the graph G with Matplotlib.Draw edge labels.To display the figure, use show() method.Exampleimport matplotlib.pylab as plt import networkx as nx plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True G = nx.DiGraph() G.add_nodes_from([1, 2, 3, 4]) G.add_edges_from([(1, 2), (2, 3), (3, 4), (4, 1), (1, 3)]) pos = nx.spring_layout(G) ... Read More

Plotting power spectral density in Matplotlib

Rishikesh Kumar Rishi
Updated on 10-Jun-2021 11:59:43

1K+ Views

To plot Power Spectral Density in Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Initialize a variable, dt.Create t, nse , r, cnse, s, and r data points using numpyCreate a figure and a set of subplots.Plot t and s data using plot() method.Plot the power spectral density.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True dt = 0.01 t = np.arange(0, 10, dt) nse = np.random.randn(len(t)) r = np.exp(-t / 0.05) cnse = np.convolve(nse, ... Read More

How to plot single data with two Y-axes (two units) in Matplotlib?

Rishikesh Kumar Rishi
Updated on 10-Jun-2021 12:02:03

10K+ Views

To plot single data with two Y-Axes (Two units) in Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create speed and acceleration data points using numpy.Add a subplot to the current figure.Plot speed data points using plot() method.Create a twin Axes sharing the X-axis.Plot acceleration data point using plot() method.Place a legend on the figure.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True speed = np.array([3, 1, 2, 0, 5]) acceleration = np.array([6, 5, 7, ... Read More

How to reverse the colormap of an image to scalar values in Matplotib?

Rishikesh Kumar Rishi
Updated on 10-Jun-2021 12:02:31

346 Views

To reverse the colormap of an image, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create random data points using x and y.Get the blue color map using get_cmap() method.Add a subplot to the current figure at index 1.Plot x and y data points using scatter() method.Create a colorbar for a scalar mappable instance.Plot x and y data points using scatter() method, with reversed colormap.Set the title of both the axes.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] ... Read More

How to embed an interactive Matplotlib plot on a webpage?

Rishikesh Kumar Rishi
Updated on 10-Jun-2021 12:00:55

2K+ Views

To show a plot on a webpage such that the plot could be interactive, we can take the following steps −Install Bokeh and import figure, show, and output_file.Configure the default output state to generate the output saved to a file when:func:'show' is called.Create a new Figure for plotting.Render the images loaded from the given URLs.Immediately display a Bokeh object or application.Examplefrom bokeh.plotting import figure, show, output_file output_file('image.html') p = figure(x_range=(0, 1), y_range=(0, 1)) p.image_url(url=['bird.jpg'], x=0, y=1, w=0.8, h=0.6) show(p)OutputWhen we execute the code, it will show the following image on your default browser.You can move the image around ... Read More

How to plot a layered image in Matplotlib in Python?

Rishikesh Kumar Rishi
Updated on 10-Jun-2021 12:12:26

928 Views

To plot a layered image in Matplotlib in Python, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create dx, dy, x, y and extent data using numpy.Create a new figure or activate an existing figure using figure() method.Create data1 and data2 to display the data as an image, i.e., on a 2D regular raster.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True dx, dy = 0.05, 0.05 x = np.arange(-3.0, 3.0, dx) y = np.arange(-3.0, 3.0, ... Read More

How to get alternating colours in a dashed line using Matplotlib?

Rishikesh Kumar Rishi
Updated on 10-Jun-2021 12:13:44

475 Views

To get alternating colors in a dashed line using Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplotsGet the current axis.Create x and y data points using numpy.Plot x and y data points with "-" and "--" linestyle.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True ax = plt.gca() x = np.linspace(-10, 10, 100) y = np.sin(x) ax.plot(x, y, '-', color='red', linewidth=5) ax.plot(x, y, '--', color='yellow', linewidth=5) plt.show()OutputRead More

Advertisements