Tags down


Adding category axis to matplotlib matshow

By : zatan
Date : July 31 2020, 05:00 AM
this one helps. I have 300 items belonging to several categories: , Like you said, just adding the lines:
code :

Share : facebook icon twitter icon

matplotlib matshow labels

By : user2234183
Date : March 29 2020, 07:55 AM
wish help you to fix your issue What's happening is that the xticks actually extend outside of the displayed figure when using matshow. (I'm not quite sure exactly why this is. I've almost never used matshow, though.)
To demonstrate this, look at the output of ax.get_xticks(). In your case, it's array([-1., 0., 1., 2., 3., 4.]). Therefore, when you set the xtick labels, "ABC" is at <-1, -1>, and isn't displayed on the figure.
code :
import numpy as np
import matplotlib.pyplot as plt

alpha = ['ABC', 'DEF', 'GHI', 'JKL']

data = np.random.random((4,4))

fig = plt.figure()
ax = fig.add_subplot(111)
cax = ax.matshow(data, interpolation='nearest')



Adding a y-axis label to secondary y-axis in matplotlib

By : Prashanth Rathinavel
Date : March 29 2020, 07:55 AM
I wish did fix the issue. I can add a y label to the left y-axis using plt.ylabel, but how can I add it to the secondary y-axis? , The best way is to interact with the axes object directly
code :
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(0, 10, 0.1)
y1 = 0.05 * x**2
y2 = -1 *y1

fig, ax1 = plt.subplots()

ax2 = ax1.twinx()
ax1.plot(x, y1, 'g-')
ax2.plot(x, y2, 'b-')

ax1.set_xlabel('X data')
ax1.set_ylabel('Y1 data', color='g')
ax2.set_ylabel('Y2 data', color='b')


Heatmap with matplotlib using matshow

By : Adarsh Paul
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , Your second problem can be solved using the vmin and vmax arguments of the matshow function:
code :
matshow(board_prob, cmap=cm.Spectral_r, interpolation='none', vmin=0, vmax=1)

Interactive plot with category axis with Matplotlib

By : user1897641
Date : March 29 2020, 07:55 AM
help you fix your problem I couldn't run your code using the while loop, but I would suggest using FuncAnimation to create self-updating graphs anyway (there are plenty of examples on SO and online).
I believe your problem is with the initialization of the Line2D object. When you're passing any empty y-array, matplotlib seem to assume you're going to use numerical and not categorical values. Initializing the line with a string as a y-value seem to do the trick. You'll have to adjust the code so that the first point created makes sense for your data, but that should only be a minor annoyance.
code :
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.animation as animation
import random

# Mock categories
categories = ["cat1", "cat2", "cat3", "cat4"]

counter = 0

# Plot
x_data = [0]
y_data = ['cat1']

fig = plt.figure()

subplt = fig.add_subplot(312)
subplt_line, = subplt.plot(x_data, y_data, 'b.-')
debug_text = fig.text(0, 1, "TEXT", va='top')  # for debugging

def init():

def animate(num, ax):
    new_x, new_y = num, random.choice(categories)
    debug_text.set_text('{:d} {:s}'.format(num, new_y))
    x, y = subplt_line.get_data()
    x = np.append(x, new_x)
    y = np.append(y, new_y)
    return subplt_line,debug_text

ani = animation.FuncAnimation(fig, animate, fargs=[subplt], init_func=init, frames=20, blit=False, repeat=False)

Adding padding for the top axis of plt.matshow() not working

By : khani3s
Date : March 29 2020, 07:55 AM
it fixes the issue It appears I can answer my own question after some fairly long amount of time digging in the docs etc. and playing around.
Seems that if I move from plt.figure() to fig, ax1 = plt.subplots() then I can use fig.tight_layout() to good success.
code :
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
import matplotlib.cm as cm
from sklearn import decomposition
from sklearn.preprocessing import StandardScaler
from sklearn.datasets import make_blobs

from sklearn.decomposition import PCA 
pca_10 = PCA(10)  # project from 61 to 10 dimensions
projected_10 = pca_10.fit_transform(df)

fig, ax1 = plt.subplots(figsize=(15,4.5))
y_ticks_names = ['1st Comp','2nd Comp','3rd Comp', '4th Comp', '5th Comp', '6th Comp', '7th Comp', '8th Comp', '9th Comp', '10th Comp']
fig.colorbar(cm.ScalarMappable(norm=None, cmap='viridis'), ax=ax1)
Related Posts Related Posts :
  • name 'df' is not defined in box plot
  • Comparing dataframe columns
  • Can I Override Global Authentication for a Single Request Type in an ApiView using DRF?
  • Celery chain performances
  • Why am I getting "asynchronous comprehension outside of an asynchronous function"?
  • Creating a file from a docker container
  • doing too many write operations in django rest framework and postgres
  • How to change the order of bar charts in Python?
  • Pandas Data Frame manipulation
  • an undefined error in a simple python code- KeyError: '284882215'
  • Pandas split column in several columns throug string replacement or regex
  • how value is passed from __init__ method in pyhton as it dose not return anyhting
  • Dynamically inherit all Python magic methods from an instance attribute
  • Asking user to input certain information
  • how to test a deep learning model in a new dataset
  • Is np.fft.fft working properly? I am getting very large frequency values
  • How can you delete similar characters at the same positions in 2 strings
  • Does insert (at the end of a list) have O(1) time complexity?
  • Automatically Creating List of Dictionaries Based Upon Two Lists of Equal Length with Python
  • Discrete Cosine Transform (DCT) Coefficient Distribution
  • multiprocessing.Pool not running on last element of iterable
  • Python: sorting string non lexicographically
  • Render images from media directory Django
  • Cannot understand why more vectorization is slower than less vectorization in this case?
  • Django - Use a property as a foreign key
  • creating a function that loops if you do not enter the correct variables
  • Confused on how to store 3D matrices in HDF5 file in matlab?
  • TOTP: Can someone use the same otp within 30s and misuse it
  • is it possible to have 2 type hints for 1 parameter in Python?
  • Can someone explain what this Numpy array property is called?
  • Better way to add the result of apply (multiple outputs) to an existing DataFrame with column names
  • Selecting choice numbers
  • Create variables from list PYTHON
  • This code takes forever to run but doesn't give an error
  • "return" and "return None" behavior difference in generator
  • AttributeError: 'str' object has no attribute 'fbind' error using kivy in Python
  • Python not importing files when not inside conda environment
  • Is it possible to override a class' __call__ method?
  • Python library for live coordinated plotting in map
  • Pandas: counting consecutive rows with condition
  • How to define that a return type of method is an implementation of superclass
  • How can I print to the Visual Studio Code console in Portuguese?
  • Google Appengine Standard Python 2.7: Can't run Google Endpoints on localhost dev_appserver.py anymore
  • google appengine Unauthorized status 401
  • Don't understand cause of this IndentationError in my tic tac toe script
  • How to read in key-value pair from a json file as a pandas dataframe?
  • Can decorator decorate a recursive function?
  • How do I create a nested for loop where I have control of the initial loop index value
  • Unexpected error when creating a SQLite database using python
  • Pythonic way to write cascading of loops and if statements?
  • Python Beginner - Having trouble with multiple choice quiz program
  • Itertools return value NOT used in combinations
  • Return a list of words that contain a letter
  • From rows to columns using Peewee ORM
  • Parse large text document, to keep only "account number", and a specific keyword ("Market Value")
  • Cannot append to my list without getting a nonetype object error
  • Python Train Test Split
  • Optimizing following Python List of Dictionary operation with better solution
  • In Pandas merge colum1 value with colum2, both col data type is object and only few values are null in first column?
  • Python run multiple background loops independently
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org